Connect your own consent code
In the plugin: Tracking Nexus → Consent & privacy
On this page
If your site collects consent with its own code, or with a tool Tracking Nexus has no integration for, your code tells the plugin what the visitor allowed. This page is the developer reference. For the settings side, see Use your own consent code.
Switch it on
-
Open Tracking Nexus → Consent & privacy.
-
Choose My own code, described there as "Your site calls TrackingNexus.consent() itself".
-
Save. Until your code makes its first call, nothing is tracked.
TrackingNexus.consent() does nothing unless this option is chosen.
TrackingNexus.consent( choice )
// Call when the visitor chooses, and again whenever they change their choice.
TrackingNexus.consent({
analytics: true,
marketing: true,
ad_user_data: true,
ad_personalization: false
});
| Key | Allows |
|---|---|
analytics |
Analytics: Google Analytics 4, and attribution of the visit. |
marketing |
Advertising. Without it, ad_user_data and ad_personalization are treated as false. |
ad_user_data |
Sending user data to advertising platforms. The other platforms need both marketing and this. |
ad_personalization |
Personalised ads. Used for Google's consent signal. |
Only a value of exactly true counts; anything else, or a missing key, is false. Calling it marks the visitor as having chosen, so to record a refusal, call it with everything false:
TrackingNexus.consent({ analytics: false, marketing: false, ad_user_data: false, ad_personalization: false });
How the choice is kept
The choice is stored in this browser's localStorage under tn_preferences_v1 for 180 days, so it applies on the visitor's next page without another call, and it is shared with their other tabs. After 180 days, or if storage is blocked, the visitor counts as not having chosen until your code calls it again. Your code should therefore call it when the visitor chooses, not on every page.
TrackingNexus.status()
TrackingNexus.status();
// { ready: true, analytics: true, marketing: true, ad_user_data: true, ad_personalization: false }
It returns a copy of the decision the plugin is working with, which is handy for checking your integration. ready: false means no choice has been made yet.
When it is available
The runtime loads deferred, so window.TrackingNexus exists by DOMContentLoaded. It is absent on pages where the plugin loads no script. Guard your call:
document.addEventListener('DOMContentLoaded', function () {
if (window.TrackingNexus) TrackingNexus.consent(myCurrentChoice());
});
Bots and crawlers get a stand-in whose methods do nothing, and a visitor with an excluded role gets no script at all.
Google's consent signals
When Tracking Nexus loads a Google tag, it writes Google's consent default before any Google tag, then updates it from the choice you pass. See Google consent mode.
Questions
Why does TrackingNexus.consent() do nothing?
The option My own code isn't selected in Consent & privacy, or the page isn't running the plugin's script (tracking off, an excluded role, or a bot).
How long is a visitor's choice remembered?
180 days in that browser, shared between its tabs. Call TrackingNexus.consent() again whenever the visitor changes their choice.
Can I withdraw consent from code?
Yes. Call it again with the purposes set to false. The plugin then stops sending for those purposes.
Last updated 27 November 2026