Cookie Consent: Loading Analytics and Advertising Tags According to Consent

There’s a banner, but is GA4 running without consent? A tag inventory for cookie consent, Tag Manager consent settings, Consent Mode v2 and step-by-step verification in the browser.
Technical summary
Technology
Google Tag Manager, Google Consent Mode v2, GA4, CMP, KVKK
Topic
Loading analytics and marketing tags based on consent, and verifying it
Level
Intermediate
Prerequisites
  • Administrator access to the Google Tag Manager container
  • Ability to use browser developer tools
  • Access to the list of tags on the site
In this article7 sections

The banner looks fine on the page, and there’s a “Reject” button too. But when you open the developer tools, before the visitor has clicked anything the _ga cookie has been written and a Meta Pixel request has gone out. This is the picture we see most often in cookie consent audits. This guide explains to web teams, marketing technology owners and IT managers the technical steps for really tying tags to consent and proving it in the browser. It isn’t a legal assessment; decide with your legal counsel which category is processed on which legal basis.

Consent management can’t be set up without knowing what runs on the site. The first job is an inventory: all cookies, local storage keys and third-party requests. Looking only at the home page isn’t enough. Also scan pages with the contact form, product pages, the cart, blog posts and embedded videos; many scripts load only on certain templates and never appear in a home page scan.

For each entry in the inventory, these columns are enough: cookie or source name, domain (first or third party), retention period, loading script, purpose and category. On most sites the categories are four groups:

Category Example Before consent
Necessary Session, cart, CSRF, load balancer, consent preference cookie Works
Functional Language preference, live chat window Depends on design, usually with consent
Analytics Google Analytics 4, Matomo, heatmap tools Must not run
Marketing Google Ads, Meta Pixel, LinkedIn Insight Tag Must not run

The most abused category is “strictly necessary”. For a cookie to count as strictly necessary, it’s expected to be genuinely required for the site to provide the service the visitor requested. Being “very important for the marketing team” doesn’t mean that. The primary source for the category distinction is the cookie practices guide of the Turkish Personal Data Protection Authority; the current text is at kvkk.gov.tr.

There are three technical ways to tie a tag to consent. Which one you choose also determines how you test it:

  • Not loading the script at all: The tag isn’t added to the page until consent arrives. It’s the strictest method and also the easiest to verify.
  • Loading the script with an inert type: Many consent management platforms (CMPs) use the pattern <script type="text/plain" data-category="analytics">. The browser doesn’t run this block; when consent arrives, the tool re-inserts the block as text/javascript.
  • Loading the script and restricting its behavior: Google Consent Mode’s advanced mode works like this; it’s explained separately below.

On corporate WordPress sites, the real leak is the same tag coming in through more than one door. The “header code” field in the theme settings, the SEO plugin’s analytics module, a WooCommerce marketing plugin and Tag Manager can all load GA4 at the same time. If the CMP controls only one of them, the others run without consent. The rule is simple: all tags are managed from a single point, preferably through Google Tag Manager (GTM), and the other insertion points are closed. Search the page source for gtag/js?id=. If there are two results, you’ve found the problem.

On sites using full-page caching, there’s a second trap. If the consent state is read on the server and different scripts are written into the HTML, the cached page serves one visitor’s consent state to another. The consent decision should be made on the client side, by looking at the preference cookie in the browser. We explained conflicts between caching and personalized content in detail in the WooCommerce cache errors article.

In GTM, the correct setup starts with defining the consent default before anything else. The Consent Initialization – All Pages trigger exists for this; it runs before all other triggers. The CMP’s GTM template (most CMPs have an official template in the Community Template Gallery) is attached to this trigger and sets the default to “denied”.

If you don’t use a template, you define the default state before the GTM container code like this:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied',
    'analytics_storage': 'denied',
    'functionality_storage': 'denied',
    'personalization_storage': 'denied',
    'security_storage': 'granted',
    'wait_for_update': 500
  });
</script>

When the visitor saves their preference, the CMP sends an update according to the selected categories:

gtag('consent', 'update', {
  'analytics_storage': 'granted',
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied'
});
dataLayer.push({'event': 'consent_update'});

GA4 and Google Ads recognize consent types natively. Non-Google tags such as Meta Pixel, LinkedIn Insight Tag and Hotjar don’t read this signal on their own. This is the step most often skipped in the field. For these tags, in the tag’s Consent Settings section in GTM, “Require additional consent for tag to fire” is selected and the relevant consent type (for example ad_storage) is added. That way, even if the trigger fires, the tag doesn’t fire without consent. For the tag to run on the same page when consent is given after the page has opened, a consent_update custom event trigger should also be added to the tag; otherwise the tag only runs on the next page view and the landing page’s conversion data is lost.

When the consent overview is enabled in the container settings, the Consent Overview screen shows in a single list which tag has which consent check. Look at this list before every publish. A forgotten tag shows up there.

Google Consent Mode is an API that changes the behavior of Google tags according to the consent state. It isn’t a banner, and it isn’t consent management: the CMP collects consent, and Consent Mode carries the result to Google tags. Version 2 added the ad_user_data and ad_personalization parameters; Google requires these signals to be sent for users in the European Economic Area in Google advertising features.

Mode Without consent Note
Basic Google tags aren’t loaded, no data is sent Predictable behavior, easy to verify
Advanced Tags are loaded and send cookieless pings without writing cookies Google models the data; requires legal assessment

In advanced mode, when analytics_storage is denied, GA4 doesn’t write the _ga cookie, but it sends page view information to Google as a cookieless ping. Whether this counts as data transfer without consent is debatable, and it isn’t a decision the technical team should make alone. Until the organization reaches a decision, starting with basic mode is the more defensible default. For the official definition of the parameters, see the Google Tag Platform consent mode documentation.

To be able to show later that consent was given, the preference should be recorded not only in the browser but also on the server side. Corporate CMPs do this in their own cloud. If you’re building your own solution, as required by KVKK-focused data management, the record should have these fields:

  • A randomly generated consent ID (also kept in the preference cookie in the browser; it doesn’t identify the person directly)
  • Timestamp (UTC)
  • Accepted and rejected categories
  • Version number of the banner and policy text
  • The page address where consent was given

Storing the full IP address isn’t necessary in most cases and turns the record itself into a personal data burden. Don’t skip the version number. When the category or tag list changes, the version is incremented and the banner is shown again to visitors who consented to the old version. A record without a version field can’t explain which consent a newly added pixel relies on.

Changing the preference should be as easy as giving consent. In practice, this means a “Cookie preferences” link in every page’s footer that opens the CMP’s preference panel. When consent is withdrawn, two things are done: the relevant types are set to denied with gtag('consent', 'update', ...), and first-party cookies written earlier (such as _ga, _ga_<ID> and _fbp) are deleted. Your site can’t delete cookies written to third-party domains; this limitation should be stated clearly in the policy text.

Manage the consent record with the same discipline as the retention setup for data collected in contact forms; we explained the form side in the KVKK-compliant contact form guide.

Verifying in the browser: the check sequence

It isn’t the green ticks in the CMP panel that prove the setup is correct, but the behavior observed in the browser. Run the tests in a private window with extensions turned off. With an ad blocker on, a “no request goes out” result is misleading; the blocker has blocked it for you.

  1. First load, no interaction: Under Developer tools > Application > Cookies, only strictly necessary cookies should appear. _ga, _gcl_au and _fbp should not be there.
  2. Network tab: Search requests with the filters collect, facebook, linkedin and hotjar. In basic mode, no requests at all should go to Google; in advanced mode, the gcs=G100 parameter should be visible in outgoing requests (ad and analytics storage denied).
  3. Accept analytics only: _ga should be created and gcs=G101 should appear in GA4 requests; ad pixels should still not run.
  4. Accept all: gcs=G111 and the marketing tags’ requests should be visible.
  5. Withdraw the preference: Depending on the Consent Mode type applied, check cookies and network requests before consent and after withdrawal separately. Also verify the clearing of existing cookies according to the behavior of the consent tool in use.
  6. GTM Preview (Tag Assistant): On every event, the default and current state should appear correctly in the “Consent” tab; tags requiring consent should be in the “Not Fired” list.
  7. Different templates: Repeat the same tests on a blog post, the contact page and a page with an embedded video. For YouTube embeds, use the youtube-nocookie.com domain or a placeholder that shows a thumbnail until consent.

This test isn’t done once and shelved. When the marketing team adds a new tag to GTM, the consent setting may be left out; most leaks that open months after setup are born this way. Put the Consent Overview check before every GTM publish, and an inventory scan once a quarter, into the maintenance calendar. For the performance impact of third-party scripts, see the JavaScript budget article; tags loaded after consent also affect INP and load time.

For a cookie inventory, CMP and GTM integration and reporting of verification tests, you can get support from our web analytics and conversion tracking service.

Frequently asked questions

Because GA4 is most likely also being loaded from a second place the banner tool doesn’t see: the theme header code, the SEO plugin’s analytics module or an e-commerce plugin. Manage tags from a single point, preferably through Tag Manager, and close the other insertion points.

No. Consent Mode doesn’t collect consent; it carries the preference collected by the CMP to Google tags. Obtaining, recording and allowing withdrawal of the preference is still the job of the consent management tool.

Strictly necessary cookies are those the site needs to provide the service the visitor requested, and they usually run before consent. They still need to be listed and explained in the cookie policy. Before putting a cookie in this category, document that it really fits the definition.

No. The relevant first-party cookies have to be deleted by the CMP or your own code. Your site can’t delete cookies written to third-party domains; this limitation should be stated clearly in the policy text. Assess how your data processing preferences on the web align with retention and access processes within the scope of KVKK technical and administrative measures consulting.

Support

Contact us for support or a discovery session on this topic.

Contact form
[email protected]

Eretek Web

We build and maintain corporate websites, WordPress and CMS platforms, intranet and SharePoint portals, document management, and form and approval workflows, and keep them secure and up to date.

Knowledge Center

Other articles