[SOLVED] GTM isConsentGranted always return true

Issue

This Content is from Stack Overflow. Question asked by Killesk

I’m trying to update the consent state of the analytics_storage using the updateConsentState API and it’s always returning true. Here is my tag code:

const log = require('logToConsole');

const updateConsentState = require('updateConsentState');
const setDefaultConsentState = require('setDefaultConsentState');
const isConsentGranted = require('isConsentGranted');


setDefaultConsentState({
  analytics_storage: 'denied',
  'wait_for_update': 500
});
updateConsentState({
  analytics_storage: 'denied'
});


log(isConsentGranted('analytics_storage'));

// Call data.gtmOnSuccess when the tag is finished.
data.gtmOnSuccess();

Any idea what I’m doing wrong?



Solution

I found some official documentation here

It stated:

The update is guaranteed to be processed in this container before any
queued items in the data layer.

When I called the ‘updateConsentState’ method, the next tag that was triggered had the correct content state.


This Question was asked in StackOverflow by Killesk and Answered by Killesk It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?