Unagi/Docs

Documentation /

Connect your cookie banner

Unagi works in two modes, and your cookie banner decides which one a visitor is in.

No cookie banner yet? Switch on Unagi's own: Settings → Cookie banner. It appears on your site, asks visitors to accept or reject analytics (two equal buttons, nothing ticked in advance), links to your privacy notice, remembers the choice, and lets people change their mind with a small "Cookie settings" button or your own footer link (onclick="Unagi.openConsent()"). Every choice goes into the consent log with the wording the visitor saw, and the dashboard shows your acceptance rate, counted without any identifier. It keeps out of the way if another banner tool is on the page. It does not support the IAB TCF standard or Google Consent Mode, so if you run Google Ads or AdSense in the EEA you may need a Google-certified banner instead.
Already have a banner? the install tag now includes data-consent="auto". It reads the common cookie banners (Cookiebot, OneTrust, CookieYes, Complianz, Osano, Termly, Shopify's privacy settings and Google Consent Mode) and switches tracking on only when the visitor has accepted analytics, and off again if they withdraw. If your banner is not one of those, or you have no banner, nothing is switched on automatically: use the manual calls below.

Without consent (the default)

This gives you honest page-view counts for everyone, but no journeys, findings about carts, or visitor profiles.

With consent

When a visitor accepts analytics in your banner, call:

Unagi.consent(true);

Unagi then stores a random visitor ID in the browser (localStorage key unagi_vid) and a session ID (sessionStorage key unagi_sid), and starts recording behaviour. It also re-sends the current page as a consented view, so the visitor's journey is complete. If they decline, call:

Unagi.consent(false);

That clears any ID Unagi stored and stops recording. Unagi remembers the choice in localStorage (unagi_consent) so it is applied on later visits.

Wiring it to your banner

Every consent tool offers a callback or event when a visitor makes a choice. Check yours for its exact name, and call Unagi.consent from it. The general pattern:

// when your banner reports "analytics accepted":
window.Unagi && Unagi.consent(true);

// when it reports "declined" or consent is withdrawn:
window.Unagi && Unagi.consent(false);

The script loads asynchronously, so also apply the saved choice when the page loads, once window.Unagi exists:

window.addEventListener('load', function () {
  if (yourBannerSaysAnalyticsAccepted()) Unagi.consent(true);
});

If you only output the Unagi tag after consent has been given, add data-consent="granted" to the tag instead.

Browsers that opt out

Visitors whose browser sends Global Privacy Control or Do Not Track are always treated as not having consented, whatever your banner says.

Your responsibility. Whether you need consent, and what your banner must say, depends on your visitors' locations and the law that applies to you (in the UK, PECR and UK GDPR). This page explains how Unagi behaves; it is not legal advice. See our data processing addendum and terms for the split of responsibilities.