javascriptgoogle-tag-managergtag.jscookieconsent

How can I extract gtag( 'consent' ) values?


Following Google instructions I am setting consent on a website I am working on. I am able to set gtag() consent through GTM and everything else, I was wondering: how do I get back the values that user set in gtag('consent')? (such as default|update and ad_user_data,functionality_storage, etc.)

The Google documentation explains that gtag() has a gtag('get') option, but gtag('consent') seems to be a completely different option on which gtag('get') does not work, and I cannot retrieve values set.


Solution

  • It is possible to use this function:

    window.google_tag_data.ics.getConsentState("analytics_storage");
    

    0 indicates no consent (denied), and 1 signifies consent has been granted.