trigger tags after cookie consent is accepted with 3rd party vendor (OneTrust)

Bronze Contributor
Bronze Contributor

hello - we are working through a OneTrust cookie consent manager implementation on our sites. the tag is implemented within Tealium and we have a cp.variable capturing which cookie categories the user opted into, to trigger our tags. Right now, when the cookie is accepted, the tags do not fire until you interact with the site in some way. Is there a way to trigger the tags to fire once the user accepts the cookie consent? 

My thought is that we would likely need to make a manual utag.view call using a JavaScript extension when the cookies are accepted, but not sure how to set that up. I looked into referecing the cp.variable we created, but that does not appear to included/updated in the data layer until the user interacts with the site after accepting or declining the cookie consent.  

Any help would be appreciated.



trigger tags after cookie consent is accepted with 3rd party vendor (OneTrust)

Employee Emeritus

That is correct! You will manually need to trigger a utag,view() call once the user opts-in. In this utag.view() call, you will need to pass the utag_data object or any variable that contains the data layer for that page.

Once the utag.js file runs, it will automatically read the OneTrust cookie and place it into the appropriate cp.{variable}. This variable can then be used as a load rule for the tags.

trigger tags after cookie consent is accepted with 3rd party vendor (OneTrust)

Employee Emeritus

Hi @bresulli 

You are correct that you would want to trigger a manual view call with utag.view(). 

1. If you have jQuery implemented on your site, you could use the jQuery Extension to target the Submit Button,

mattressfirm | dwmattressfirm 2020-05-15 10-25-06.png 

2. or you could use a javascript extension and set up an event listener:

document.getElementById('ConsentButton').addEventListener('mousedown', function () {

3.  Or ideally, you could have a developer option #1 or #2 from within your source code.


Once the Submit button is clicked, utag.view will fire, the OptanonCookie will be set and the cookie can be leveraged with Load Rules for each Category.  With the Load Rules applied to each tag, the Tags will fire according to what the use has chosen.


Please let me know if this helps.



trigger tags after cookie consent is accepted with 3rd party vendor (OneTrust)

Gold Contributor
Gold Contributor

 I have a similar but slightly complicated issue-

Say I have 5 tags on the page out of which 2 tags fire by default without user consent. Once user provides consent, I need to fire rest of the tags.

The utag.view call on the button click essentially triggers all tags (including the ones that fire without consent) which results in tags firing multiple times.

How can I overcome this challenge?


trigger tags after cookie consent is accepted with 3rd party vendor (OneTrust)

Employee Emeritus

Hi @ksugam 

A solution to this would depend on how things are setup within your website and Tealium account. Here are some general approaches that will work, but may need to be tweaked depending on your setup.


Method 1

If you know that two tags will fire by default.  Once consent is granted, you can specify what tags are triggered in a utag.view() call.  It accepts an array of UIDs as one of it's parameters.

utag.view(data object, callback function, array of UIDs)

So if Tags 1 and 2 fire at page load.  You can configure your event listener to fire utag.view({data object, null, [3,4,5])

Caveat is that you need to ensure that this function is kept up to date.  If you turn off a tag in TiQ and do not update the utag.view call to remove the UID from the array, the call breaks and no tags fire period.


Method 2

Pass an event variable into the utag.view call, then set up a load rule on the 2 default tags to not fire on that event.

Ex.  Page loads, Tags 1 and 2 fire > User opts into tracking and click ok > utag.view({"tealium_event": "opt_in"}) 

Then set up a load rule on tags 1 and 2 within TiQ that only fires the tags when tealium_event does not equal "opt_in")


I prefer method two, but of course, it may depend on how your set up is.  Also since Tealium is run on Javascript, if you can think of an alternative solution, a javascript extension is a powerful tool.


Hope this helps!