Skip to main content

Google tags with gtag, without GTM

This page explains how to hold the Google tag (gtag.js) until the visitor gives consent, when the tag is in the page code and not in a Google Tag Manager container. It matches the Basic mode of Consent Mode: see Consent Mode with gtag.

v2 banner

The v2 banner cannot mark a script with a Consent Mode purpose. If you do not know which banner your site uses, read Which banner your site is using.

Who this is for​

This is for you if you pasted gtag.js into the HTML and want no request to reach Google before the visitor's choice. For Advanced mode, leave the tag unmarked and see Consent Mode with gtag.

Prerequisites​

Before you start, check that:

  • the site loads the banner snippet, in the <head>, before the Google tag;
  • Google Consent Mode is on in the Avacy dashboard: in Cookie Banner, then Advanced settings, Support for Google Consent Mode must show Activate. To turn it on, read the guide Google Consent Mode: what it is and how to turn it on (in Italian);
  • there is at least one published custom vendor with a preemptive blocking URL. You need it even if the scripts are marked by you, as on this page, and not by the WordPress plugin: the blocking URL is what turns on the add-on that unblocks the scripts after consent. To set it, read Mark scripts and iframes.

Steps​

  1. Change the type of every Google script to text/avacy-blocked.
  2. For the external gtag.js script, move the address from src to data-avacy-src.
  3. Add data-avacy-requires="gcm:purpose:N" to every script, where N is the purpose number from the table below.

Example with a GA4 tag blocked until consent to the analytics purpose.

<script type="text/avacy-blocked"
data-avacy-src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"
data-avacy-requires="gcm:purpose:4"></script>

<script type="text/avacy-blocked"
data-avacy-requires="gcm:purpose:4">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>

Replace G-XXXXXXXXXX with your ID. The inline script stays after the external script, so gtag('config', ...) finds gtag.js already loaded.

The number map​

The number after gcm:purpose: is the id of the Google purpose in the banner's preferences panel, and it maps to a Google consent type.

NumberGoogle consent typePurpose in the panel (English)
1ad_storageManaging cookies or advertising device identifiers
2ad_user_dataSharing data with Google for its own advertising purposes
3ad_personalizationReceiving personalized advertising
4analytics_storageActivation of Google Analytics features
5functionality_storageStoring technical settings
6personalization_storageContent personalization
7security_storageTracking for security purposes

The definitions of the ad_storage, analytics_storage, ad_user_data and ad_personalization consent types are on Google's Consent Mode page.

Write the numbers of the purposes the tag uses, for example gcm:purpose:4 for analytics or gcm:purpose:1,2,3 for advertising. With several ids, the banner unblocks the tag only if the visitor grants all the listed purposes.

What happens after the choice​

After the choice, the banner writes the consent update to the dataLayer, then unblocks the scripts whose consent is granted. With Reject all the scripts stay blocked. A tag that has already run keeps going until the page reloads, even if the visitor withdraws consent.

Verify​

  1. Open the page in a private window. No request to googletagmanager.com appears in the Network panel.
  2. Choose Accept cookies. The request to gtag.js appears.
  3. Clear the site data, reload and choose Reject all. No request goes to Google.

To check the order in the dataLayer, see Verify the blocking.

Common problems​

The tag never runs: check the custom vendor with a blocking URL, that the vendor list is published, and that Support for Google Consent Mode shows Activate. With Consent Mode off, the gcm framework is missing: the gcm:purpose:4 requirement falls back to the custom vendor in the same marking and, without a custom:vendor:... requirement, the tag stays blocked.

The tag runs with Reject all: data-avacy-requires is probably empty: an empty attribute requires nothing, and the banner unblocks the element at the first valid choice. Write gcm:purpose:N.

The tag stays blocked after Accept cookies: the marking may be unreadable. See Mark scripts and iframes.

Consent Mode default written by hand: do not add your own gtag('consent', 'default', ...). If the page already has one, the banner does not send its own.


Last updated: 27/10/2026.