How to get current consent state for user?

Gold Contributor
Gold Contributor

Hello,

In "Tealium, GDPR, and Data Privacy" whitepaper (from Feb 27th), on page 18 I've read that it's possible to get consent state by using js function "getConsentState()". However, whenever I try to map that function as a UDO variable and call it in console, i get back info that it's undefined although it should be either array (in case partial category consent was provided) or a value of 1 (optin), -1 (optout) or 0 (not specified).

What am I doing wrong here?

 

Thanks

8 REPLIES 8

How to get current consent state for user?

Tealium Employee

Hi @amarkic

The call is actually:

utag.gdpr.getConsentState()

 

You are correct that it will return "1" for Opt-In, "-1" for Opt-Out, "0" for no consent given.

Partial consent will be an array and each item will be an object.

[
{ct:1},
{ct:0},
{ct:0},
...
]

Let me know if this helps!

 

 

How to get current consent state for user?

Gold Contributor
Gold Contributor

EDIT: Never mind, found a notification from two days ago that explains everything. Thanks :)

Hi Dan,

unfortunatelly, it's not working... It seems that utag.gdpr is not defined...

con1.jpg

con2.jpg

How to get current consent state for user?

Tealium Employee

@amarkic

Apologies that it didn't work for you. Based on my quick testing, it appears the code hasn't been published. I just tried on a site that doesn't have Consent Manager enabled and saw this same error, but on a site with Consent Manager enabled it did work. Are you able to open the utag.js file in the Developer Tools Sources tab and see if utag.gdpr exist in the contents of the file? If not, then the contents aren't being published to production.

I hope this points you in the right direction, if not you'll likely need to reach out to your Account Manager for support so they can loop in an Engineering to look at the configs and your site to see the cause.

Cheers,
-Dan

How to get current consent state for user?

Gold Contributor
Gold Contributor

It's working, but it requires "Consent prompt management" to be active in "My IQ" tab...

How to get current consent state for user?

Gold Contributor
Gold Contributor

I would like to map the value of the consent state to a Google Analytics custom dimension (we are omitting GA from our consent manager scope). Can someone help with what are the steps to be able to get this value into a variable so I can map it in the GA tag?

How to get current consent state for user?

Tealium Employee

@Krasner

You'll probably want to use a JS extension and leverage the following sample code.

var cs = utag.gdpr.getConsentState();
if (typeof cs != "undefined") {
if (cs == 1) utag.data.consent_state = "grant_full_consent";
else if (cs == 0) utag.data.consent_state = "no_consent_given";
else if (cs == -1) utag.data.consent_state = "decline_consent";
else if (typeof cs === "object") utag.data.consent_state = "grant_partial_consent";
}

 

Full disclosure, this is custom code and will need to be fully tested before used in a production environment.

Be sure to declare consent_state as a UDO var and then you can map it within the GA tag.

Hope this helps!
-Dan

How to get current consent state for user?

Moderator
Moderator

You're my hero @dan_george!. #InAwe

If you liked it then you should have put a kudo on it!

How to get current consent state for user?

Gold Contributor
Gold Contributor

Thanks @dan_george, that worked great!

Public