Stape
Search
Try for free

Consent Parser variable for Google Tag Manager server container

Published
Sep 19, 2024

Consent Mode is a feature by Google that allows websites to adjust how they track users based on their consent choices regarding cookies, advertising, analytics, and other categories of data processing.

Stape created a Consent Parser variable that reads the encoded Consent Mode v2 string from the ‘gcd’ standard parameter of GA4 hit, decodes it, and returns the consent states for various categories (e.g., ad_storage, analytics_storage) in a readable format. This helps determine what data can be collected and processed based on user preferences.

This variable is useful for websites using Consent Mode to manage user privacy preferences, especially in the context of privacy laws like GDPR and CCPA. By decoding the consent string, server-side tags can selectively fire or avoid firing based on the user's consent, ensuring compliance with legal requirements.

2. Download the Consent Parser variable from GitHub.

Consent Parser variable from GitHub

3. Import the variable to server Google Tag Manager by clicking Templates → New Variable Template → Click three dots in the top right corner → Click import → Add template that you’ve recently downloaded → Click Save.

Consent Parser variable

4. Go to Variables → New → Choose ‘Consent Parser’ → Click Save.

The variable works based on the ‘gcd’ parameter that collects GA4 automatically if your consent banner works with Google Consent Mode support.

The variable itself will find ‘gcd’ in the incoming hit and decode all the details in it into separate categories.

Consent Parser variable preview

In the variable Analytics Debugger OpenAPI is used to decode the consent string.

This is a handy tool for parameter debugging that you can use online:

  • Collect the encoded Consent Mode string from a user session or test event.
  • Paste the string into the decoder tool to view the decoded values.
  • Compare the decoded consent states with what you expect to see based on the user's consent choices.

Conclusion

Here are three benefits of using the Consent Parser variable in server-side Google Tag Manager:

  1. Compliance with privacy laws: this variable ensures websites adhere to privacy regulations like GDPR and CCPA. It enables selective data collection and processing based on user consent, helping you remain compliant with legal requirements.
  2. Efficient consent management: easily manage and implement user consent preferences for categories such as analytics and ads for tags on server GTM container. This makes it simpler to control which server-side tags should fire, based on real-time user consent.
  3. Respect user choices while still gathering valuable data when consent is granted. This boosts trust with users by limiting tracking to the agreed-upon categories.

And if you’d like to read more about Consent Mode, here you can find some useful articles:

Tagged with:gtm server

Host your GTM server at Staperight now!