Skip to main content

Kickbite Tracker — Consent Callback Fix

Written by Juan Garzon

Problem

script.js and u.js only load on page refresh after consent. First session (with UTMs + referrer) is lost.

Required Behavior

On consent accept → immediately inject both scripts without a page reload.


Implementation by CMP

OneTrust

javascript

function OptanonWrapper() {   if (OnetrustActiveGroups.includes('C0002')) { // Performance/analytics category     injectKickbite();   } }

Cookiebot

javascript

window.addEventListener('CookiebotOnAccept', function () {   if (Cookiebot.consent.statistics) {     injectKickbite();   } });

Usercentrics

javascript

window.addEventListener('UC_UI_CMP_EVENT', function (e) {   if (e.detail && e.detail.type === 'ACCEPT_ALL') {     injectKickbite();   } });

Google Tag Manager (Consent Mode)

In GTM, create a Custom Event trigger on consent_update, then fire a tag that calls injectKickbite().


Shared Injection Function

javascript

function injectKickbite() {   if (window.__kickbiteLoaded) return; // prevent double-load   window.__kickbiteLoaded = true;    var scripts = [     'https://your-domain.com/script.js',     'https://your-domain.com/u.js'   ];    scripts.forEach(function (src) {     var s = document.createElement('script');     s.src = src;     s.async = true;     document.head.appendChild(s);   }); }

Why This Works

At the moment of accept, window.location.href still contains the original UTM parameters and document.referrer still holds the traffic source. No data is lost.

Checklist

  • Confirm which CMP is used across BE, FR, NL, DE, AT, CH

  • Implement the consent-change callback for that CMP

  • Add the injectKickbite() function with double-load guard

  • Verify in browser DevTools: scripts fire immediately on accept (no reload)

  • Confirm UTM params are captured in the first Kickbite request

Did this answer your question?