Skip to content
  1. Home
  2. Help center
  3. For developers
  4. The cookie banner and the KO counter — passing consent

The cookie banner and the KO counter — passing consent

Last updated:

By the end of this article your cookie consent banner will control the KO counter: when consent is denied, the counter sets no cookies and sends no visit data; when consent is withdrawn, it removes what it has already stored. The counter must already be installed: Connecting a website.

This article covers the technical side only. What kind of consent your site needs, and in what form, is for your lawyer to decide; the counter carries out the decision it is given.

What the counter does on its own

The counter does not read your banner. It does not look at the consent platform’s cookies, at dataLayer or at Google Consent Mode. Your site’s code passes the visitor’s choice to it with one call, described below. Until that call happens, the counter assumes there are no restrictions and works as usual.

When analytics is denied, the counter:

  • stops writing cookies, localStorage and sessionStorage;
  • stops sending visit data and events, and stops phone number substitution;
  • deletes its cookies (_ko_client_id, _ko_touch_id, _ko_touch_id__session, _ko_session_id, _ko_visit_id, _ko_uid, _ko_tracks_email_id) and its storage keys — everything that starts with _ko_ and ko..

Form submissions still go through when consent is denied. Sending a form is the person’s own request, so the counter delivers the lead in any state. The lead will not be linked to a visit: the cookie that links them was never written.

KO consent does not block advertising pixels. The counter stores a separate ads key, but nothing depends on it today. If the page has advertising pixels, the counter passes goals to them regardless of consent. Your banner blocks the pixels and their loading — the same way it blocks your other tags.

The simplest and most reliable approach: the counter is not on the page until the person allows analytics. Before the choice, there is not a single request to KO and not a single cookie.

Take the counter address from your connection’s install snippet — https://cdn.kodata.pro/site/?hash=… — and insert the counter from your banner’s consent handler:

<script>
  window.koLayer = window.koLayer || [];

  // Call this from the banner on every choice the person makes — the first one and any change.
  function koConsent(analytics, ads) {
    window.koLayer.push(['consent', 'update', [{ analytics: analytics, ads: ads }]]);

    if (analytics && !window.koCounterLoaded) {
      window.koCounterLoaded = true;
      var s = document.createElement('script');
      s.async = true;
      s.src = 'https://cdn.kodata.pro/site/?hash=YOUR_HASH';
      document.head.appendChild(s);
    }
  }
</script>

Most consent platforms have a “choice changed” event or callback — call koConsent from there. If your site already loads tags through Google Tag Manager, a Custom HTML tag with an analytics consent trigger does the same job.

The koLayer entry is needed here too: once the counter has loaded, it passes a withdrawal of consent to it (see below).

Or declare a denial before the counter loads

If the counter has to be on the page at all times and permission comes later, declare the default state in ko_options — before the install snippet:

<script>
  var ko_options = window.ko_options || {};
  ko_options.consent = { analytics: false, ads: false };
</script>
<!-- the counter's install snippet goes here -->

The counter loads but sets no cookies and sends no visit requests. When the person allows analytics, pass that with the same call:

window.koLayer.push(['consent', 'update', [{ analytics: true, ads: false }]]);

The visit starts on the next page. The counter remembers the permission given on the current page, but it does not reopen a visit that has already been silenced. The first page after consent stays without a visit — if that page matters (a one-screen landing page), use the approach from the previous section.

An early koLayer entry does not work in place of ko_options for a default denial: the counter processes its queue at the end of loading, and cookies get written before that.

If you declare a default denial but the person already made a choice on an earlier page, pass the saved choice in ko_options.consent, not the denial.

A person can change their mind after the counter is already running. The call is the same:

window.koLayer.push(['consent', 'update', [{ analytics: false }]]);

The counter stops at once and erases what it stored. Substituted phone numbers on the page stay until a reload: the counter no longer updates them, but it does not change them back either. If that matters too, reload the page after the withdrawal — our own banner on this site does that.

Denying one key leaves the other alone: { analytics: false } does not change ads.

Values the call accepts

Keys are the short analytics and ads, or the Google Consent Mode names if your banner already produces them in that form:

KeyWhat it means for the counter
analytics or analytics_storageAnalytics: cookies, the visit, events, number substitution
ads, ad_storage, ad_user_dataAdvertising. A denial in either Consent Mode key is a denial

Values: true / false, 1 / 0, 'granted' / 'denied'. The counter treats anything else as “not specified”, not as a denial, and leaves the state unchanged.

The full list of calls is in the counter reference.

Check it

  1. Open the site in a private window and deny analytics.
  2. In DevTools → Application → Cookies: there are no _ko_* cookies.
  3. In the Network tab, filter by metrika: there are no requests.
  4. Run ko.consent.get() in the console — analytics: 'denied'. If the counter loads only after consent, ko will not exist at all — that is a correct answer too.
  5. Repeat with consent: _ko_* cookies and visit.php requests appear, and ko.consent.get() shows 'granted'. With a default denial through ko_options, check on the second page after consent.
  6. Withdraw consent: the _ko_* cookies are gone, and there are no new metrika requests.

With ?ko_debug in the address, the counter logs every change to the console as ko.consent analytics=… ads=… source=…. source shows where the choice came from: options — from ko_options, api — from a call.

If it does not add up

Consent was denied, but _ko_* cookies are there. The banner does not call koLayer — the counter does not know about the denial and works as if there were no banner. Run ko.consent.get() in the console: analytics: 'none' means the call never happened.

A default denial is set, but the first cookie still appears. The denial was passed as a koLayer entry before the counter loaded rather than through ko_options.consent, or ko_options is declared after the install snippet.

Permission was given, but there is no visit on this page. That is expected with a default denial through ko_options: the visit starts on the next page.

There is no consent, but an advertising pixel fires. The counter does not block pixels by consent — your banner or a tag manager rule does.