Skip to main content

Cookie Consent & Kickbite Trackers — First Session Fix

How to ensure Kickbite trackers fire immediately after cookie consent, so the first session and UTM data are captured.

Written by Juan Garzon

The Problem

In markets using a Cookie Management Platform (CMP), the Kickbite trackers (script.js and u.js) may only fire after a page refresh following cookie consent acceptance.

This means the first session is lost — including UTM parameters and referrer data — which directly impacts attribution accuracy.


Expected Behavior

When a user clicks "Accept" on the cookie banner, both Kickbite scripts should be injected immediately — without requiring a page reload. At the moment of acceptance, window.location.href still contains the original UTMs and document.referrer still holds the traffic source.


How to Fix It

The CMP or tag manager must listen for a consent-granted event and dynamically inject the Kickbite scripts in that callback. The exact implementation depends on the CMP in use:

  • OneTrust — Use the OptanonWrapper callback and check OnetrustActiveGroups

  • Cookiebot — Listen for the CookiebotOnAccept event

  • Usercentrics — Listen for the UC_UI_CMP_EVENT event

  • Google Tag Manager — Trigger a tag on the consent_update custom event

In all cases, the injection function should include a double-load guard to prevent the scripts from being loaded twice (once on accept, once on reload).


Technical Implementation

Use the following shared injection function. Replace the script URLs with your actual Kickbite script paths:

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);
  });
}

CMP-specific examples:

OneTrust

function OptanonWrapper() {
  if (OnetrustActiveGroups.includes('C0002')) {
    injectKickbite();
  }
}

Cookiebot

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

Usercentrics

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

Google Tag Manager
Create a Custom Event trigger on consent_update, then fire a tag that calls injectKickbite().


How to Verify

  1. Open the site in an incognito window

  2. Open browser DevTools → Network tab

  3. Click "Accept" on the cookie banner

  4. Confirm that script.js and u.js appear in the network requests immediately — without a page reload

  5. Check that the request URL or payload includes the original UTM parameters

Did this answer your question?