Server GTM Variable Template: Consent State (v2.0)
Server-side GTM receives consent as a string like 13r3r3r3r5l1. Fine if you happen to read encoded consent strings, but not so much fun if you don't. To help translate, I've built a variable template that decodes it into something actually useful.
The problem
In a web container, consent is easy. With Consent Mode, you've got the built-in consent checks and can set your own consent trigger rules too. But in a server container you just get the raw gcd and gcs values. Both opaque parameters, holding the consent signals in a format designed for machines rather than us squishy humans...
In this raw format, we can't put it in a trigger condition, or pass it into tags as a variable. It's not even worth passing into BigQuery as-is. So to address this, this is where my sGTM variable template comes in - you pass in the raw consent string, and output the human (and tag) readable consent choices.
What the variable does
It's an sGTM variable template that lets you:
- Choose your consent string -
gcd(has all four signals with default and update states) orgcs(ad_storage and analytics_storage only). You can even use a custom string if you so desire! - Choose the consent signal -
ad_storage,analytics_storage,ad_user_data, orad_personalization. - Choose the output format - a string, boolean or number, with your own values for granted, denied and unknown.
Note: functionality_storage, personalization_storage and security_storage are signals in Consent Mode, but Google never sends them to the server container, so no server-side template can read them unless you manually pass them in the event data.

How to get it
Head to GitHub and download the template.tpl file from it. Then in your sGTM container, go to Templates → Variable Templates → New and use the ellipses to import the file you just downloaded.
Now you're all set to add a variable in the regular way, selecting Consent State as the variable type from the list.
It's not in the Community Template Gallery yet as it's a somewhat slow process, but I'll update this post when it's there.
Feedback
I've built this the way I'd want it, which means I've almost certainly missed something obvious that someone else needs. If it doesn't do the thing you expected, or there's an output format I've skipped, drop me a message on LinkedIn or open an issue on the repo.
