DEV Community

Mehwish Malik
Mehwish Malik

Posted on

Are Your Analytics Tags Running Before Visitors Take Action?

Tags do what the rules say. If a rule says "all pages", the tag runs on every page load. That is before a click, before a form and before any banner choice.

Here is how to see it, why it happens and how to fix it.

1. See what already ran

Open your site in a private window. Do not touch the banner. Paste this in the console:

performance.getEntriesByType('resource')
  .map(r => r.name)
  .filter(u => /google-analytics|doubleclick|facebook\.com\/tr|px\.ads\.linkedin|clarity\.ms|hotjar/.test(u));
Enter fullscreen mode Exit fullscreen mode

Also check the cookies:

document.cookie.split('; ').map(c => c.split('=')[0]);
Enter fullscreen mode Exit fullscreen mode

If you see URLs in the first result or names like _ga and _fbp in the second, something ran before consent.

2. Find out why

Four causes show up most often:

  • A snippet pasted straight into the site header
  • A GTM tag with an All Pages trigger and no consent check
  • A CMS plugin or theme that injects its own script
  • A consent banner that loads after the tags

The last one is a load order problem. The banner is there, but it arrived late.

3. Set the default before anything else loads

If you use Google tags, set a denied default before gtag.js or GTM loads:

window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }

gtag('consent', 'default', {
  ad_storage: 'denied',
  analytics_storage: 'denied',
  ad_user_data: 'denied',
  ad_personalization: 'denied',
  wait_for_update: 500
});
Enter fullscreen mode Exit fullscreen mode

When the visitor accepts, update the state:

gtag('consent', 'update', {
  analytics_storage: 'granted'
});
Enter fullscreen mode Exit fullscreen mode

4. Wire it up in GTM

Fire the default from a tag on the Consent Initialization trigger. That trigger runs before all others. Then open Advanced Settings on each tag and set its consent requirements.

One warning. Consent Mode is a signal for Google tags. Not every tool reads it. Check Meta, LinkedIn and recording tools one by one. Block them until consent if they ignore the signal.

5. Test again

Repeat step 1 in a fresh private window. The result should be empty. Then click accept and run it again. Requests should now appear. Test the reject button too. People often forget it.

What to gate

Not every cookie needs a gate. Essential cookies do not. The SeersAI blog on which cookies B2B sites need consent for explains the split. Analytics, marketing and tracking cookies sit on the consent side.

When hand coding gets heavy

This works for one site. It gets harder with many sites, many tools and many regions. A consent platform can carry that load. SeersAI sets the default state, updates it when a visitor chooses, blocks scripts that ignore consent signals and stores the record. It also supports Google Consent Mode v2.

Run the console test once a month. Tags change more often than anyone expects.

Top comments (0)