Skip to main content

Debug mode and Google tag order

Google tags read the consent state when they start. If they start too early, they can read the wrong state. This page explains the warning Avacy prints in the browser console, how to turn on debug mode, and what to do when a tag is late.

NOTE: This page applies to the new Avacy banner (v3). The previous banner does not run this check and has no window.Avacy.

Google tag order​

Why the order matters​

When the Avacy core starts, it checks whether a Google tag (gtag.js, Google Tag Manager, analytics.js) ran before:

  • the Google Consent Mode default call, or
  • the TCF stub.

A Google tag that runs earlier may read the wrong consent state.

The check runs once, when the core starts. The exception is the case with only gtm.js, described in How the result is decided. It runs only if the configuration has Google Consent Mode or TCF. Without either, it prints nothing. It never blocks the consent update.

The console warning​

When a Google tag is late, the console always shows a yellow warning (console.warn) like this one, even with debug mode off. The text is in English:

[Avacy] Google tags ran before the Consent Mode default or the TCF stub: Google may have read the wrong consent state. First check whether the late tag is served through Google Tag Gateway (GTG). If it is, follow the Avacy GTG guide: https://docs.avacysolution.com/en/avacy-tech-docs/preemptive-block/google-tag-gateway. If it is not, load the Avacy snippet before the Google tags. Guide: https://docs.avacysolution.com/en/avacy-tech-docs/preemptive-block/debug-mode-google-tag-order#google-tag-order (Google: https://developers.google.com/tag-platform/security/guides/consent)

The warning gives the steps described below in "What to do if the result is LATE" and links to this page.

The warning appears at most once per page.

If the page uses Google Tag Manager and TCF, the message is different. See GTM and TCF.

Turn debug mode on and off​

Debug mode prints more detail in the console, including the result of this check. Open the browser console and run:

window.Avacy.debugModeOn();

The call saves the flag in localStorage (key avacy:debug) and reloads the page. To turn it off:

window.Avacy.debugModeOff();

You can also turn it on with a configuration that has the console logger.

PASS and LATE​

With debug mode on, the console always prints one result. The line starts with [gcm] if Consent Mode is present, otherwise with [tcf].

  • PASS: no Google tag ran before the Consent Mode default or the TCF stub.
  • LATE: a Google tag ran first. The warning above is printed too.

The line also shows the data behind the result. It contains the time of the check in ms, the position of the default and of the first Google command in the dataLayer, the Google consent state and the TCF stub state.

Part of the lineMeaning
check at … msTime of the check, in milliseconds since the page opened.
dataLayer: default #nThe position of the consent default in the dataLayer. It is GTM template if the Avacy GTM template set it, absent if it is missing.
first Google command #nThe position of the first Google command in the dataLayer, or absent.
Google consent state (google_tag_data.ics)Google's internal consent state, with usedDefault, or absent.
Google wasSetLateValue read from Google, or absent.
Google scripts already downloaded (info only)The gtm.js, gtag/js and analytics.js files already downloaded, with the time. For information only: it does not decide the result.
TCF stubpresent, absent or not needed if the TCF is not configured.

Example:

Google tag order: PASS (check at 412 ms; dataLayer: default #0, first Google command #1; Google consent state (google_tag_data.ics): usedDefault true, Google wasSetLate: false; Google scripts already downloaded (info only): none; TCF stub: not needed)

How the result is decided​

The order of the commands in the dataLayer decides the result.

  • Consent Mode: the consent default must come before the first Google command. That is js, config or event from gtag, or the gtm.js event. If it does, the result is PASS.
  • TCF: if Google commands are already in the dataLayer and the __tcfapi stub is missing, the result is LATE. If there are no Google commands yet, the result is PASS.

A default set by a Google Tag Manager tag is not in the dataLayer. Avacy reads Google's own consent state (google_tag_data.ics) for this case. If a default was set and no Google tag had read the consent before it, the warning is not printed.

If the only Google command is gtm.js and no default is visible, Avacy waits before it warns. It waits for the page load event, 3 seconds at most. If the page is already loaded, it waits half a second. Then it checks once more.

A custom dataLayer name is not read by the check.

What to do if the result is LATE​

  1. Check whether the late tag uses Google Tag Gateway (GTG). See How to verify if a tag is enrolled in GTG.
  2. If it does, follow the Google Tag Gateway and Consent Management page.
  3. If it does not, load the Avacy snippet before the Google tags.
  4. If you use Google Tag Manager with TCF, see GTM and TCF.

Google guide: Set up consent mode on websites.

GTM and TCF​

With Google Tag Manager and TCF, you cannot load the Avacy snippet before GTM. The banner starts later. What must come first is the TCF stub. It is a small script that installs window.__tcfapi and queues the calls until the banner starts.

If GTM starts without the stub, the result is LATE. The console warning is this one (the text is in English):

[Avacy] Google Tag Manager ran before the TCF stub: Google may have read the wrong consent state. With GTM and TCF, add the TCF stub in the <head>, before the GTM snippet. Guide: https://docs.avacysolution.com/en/avacy-tech-docs/preemptive-block/debug-mode-google-tag-order#gtm-and-tcf

This happens when all of these are true:

  • TCF is in the configuration.
  • Google commands are already in the dataLayer. Either the Avacy GTM template is active, or the first command is the gtm.js event.
  • There is no __tcfapi function.

To fix it, load the stub as a synchronous script in the <head>. Put it before the GTM snippet and before any script that calls __tcfapi.

<head>
<!-- 1. TCF stub: synchronous, before GTM. -->
<script src="https://<tenant>.avacy-cdn.com/v3/tcf-stub.js"></script>
<!-- 2. GTM snippet. -->
<!-- ... -->
<!-- 3. Avacy banner. -->
</head>

<tenant> is a placeholder: use the same domain as the banner snippet. This address always serves the latest version of the stub. If the stub is already on the page, the banner does not overwrite it.

The stub is the IAB one, the @iabtechlabtcf/stub package.

The guide to the Avacy CMP template for Google Tag Manager is Integration via Google Tag Manager (in Italian).

Verification​

  1. In the console, run window.Avacy.debugModeOn(). The page reloads.
  2. Look for the [gcm] Google tag order line (or [tcf] Google tag order).
  3. With PASS, the order is correct. The yellow [Avacy] Google tags ran before… warning no longer appears either.

Common problems​

The most frequent issues:

  • No message in the console: the configuration has neither Consent Mode nor TCF, or debug mode is off and the result is PASS;
  • The warning stays even with the snippet first: check that no component inserts a Google tag before the banner in the HTML, for example the CDN, a plugin or the theme;
  • The snippet is first but the default is missing: the default is sent by the installation snippet, only in the variants with Google Consent Mode. Check in Advanced settings > Support for Google Consent Mode;
  • The dataLayer has another name: the check does not see it.

Last updated: 10/11/2026.