Developer hooks
For developers building on the client plugin, for example native short link support in an analytics plugin. Everything goes through filters, so your code needs no function_exists() checks: with the client plugin missing or not connected, the filters simply return null.
Hooks#
| Hook | What it gives you |
|---|---|
apply_filters( 'nlc_site', null ) | This site’s connection: the site API base and read-only key, the click ID name, and whether the bridge is on. |
apply_filters( 'nlc_site_api', null, $path, $query ) | A ready-made call to the site API, like click/{id} or links. |
nlc_analytics_native | Return true when your analytics plugin records short link visits itself. |
nlc_site_domain | Change the website domain sent when the site key is made. |
nlc_bridge_enabled, nlc_bridge_attributes | Turn the bridge script on or off, or change its script tag attributes. |
do_action( 'nlc_site_ready', $site ) | Fires once the site key is ready. |
Read the connection#
$nl = apply_filters( 'nlc_site', null );
// null, or [
// 'version' => '1.0.0',
// 'site' => 'brand.com',
// 'click_param' => 'nlc',
// 'bridge' => true,
// 'bridge_url' => 'https://go.brand.com/_nl/bridge.js',
// 'track_event' => 'Short link visit', // or null
// 'api' => [ 'base' => 'https://go.brand.com', 'key' => 'nlsk_…' ], // null until ready
// ] Call the site API#
The filter gets the key if needed and renews it when refused. It returns an array or a WP_Error, or null when the client plugin isn’t there.
$links = apply_filters( 'nlc_site_api', null, 'links', [] );
$clicks = apply_filters( 'nlc_site_api', null, 'clicks', [ 'after_id' => 0, 'limit' => 500 ] );
$one = apply_filters( 'nlc_site_api', null, 'click/K3v9QpX2aB7mN1zR', [] ); Tell the bridge you handle it#
add_filter( 'nlc_analytics_native', '__return_true' ); This stops the bridge sending its own “Short link visit” event to Nahnu Analytics.
React when the key is ready#
add_action( 'nlc_site_ready', function ( array $nl ) {
// Send $nl['api']['base'] and $nl['api']['key'] to your platform.
} ); In the browser#
window.NahnuLinks and the nahnulinks:click event, fired with the link a visitor came from:
document.addEventListener('nahnulinks:click', function (e) {
var click = e.detail;
// click.link.short_url, click.link.title, click.country, click.device, click.route ...
}); The click ID is kept in the tab’s session storage; no cookies are used.
Full guide#
The full guide is in the plugin, at docs/nahnu-analytics-integration.md. The site API itself is described in Site API.


