Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tag Manager - Adding trigger firing exception based on cookie value

I need help in setting up the exception in trigger firing based on specific cookies value.

It should look like that: If "my_custom_cookie_name" value is "0" then the tag isn't fired. Could you please help me with that? Where should I start? Which parameters should I pick to create such a condition?

like image 267
Filip Kapusta Avatar asked May 28 '18 11:05

Filip Kapusta


People also ask

Does Google Tag Manager use cookies?

So does Google Tag Manager use cookies? No, it does not. The only exception is Preview and Debug mode. Once you enable it, GTM sets several first-party cookies on your browser.

Can Datalayer variable be used as a trigger?

A data layer is a JavaScript object that is used to pass information from your website to your Tag Manager container. You can then use that information to populate variables and activate triggers in your tag configurations.

Why is my GTM tag firing twice?

You have enabled preview mode of Google Tag Manager. If you still see Google Tag Manager firing twice, another reason might be GTM's preview mode. When Preview and debug mode is enabled, it sends two requests to Google Tag Manager: one to load gtm.


2 Answers

For example, if you want to add a condition on the trigger of a pageview :

1. You need to create a custom variable (cookie first party) :

enter image description here

The value is the name of your cookie

2. Then, you need to create your trigger with a specific condition :

enter image description here

  • Select "on specific pages"
  • The variable is your cookie name
  • The condition is "Equal to"
  • The value is the cookie value
like image 53
Idov Mamane Avatar answered Oct 20 '22 22:10

Idov Mamane


You can read a first party cookie variable with the name of your cookie - just go to variables/new and select 1st-party-cookie as variable type and enter the name of the cookie. Name your variable as you like it, e.g. "myCookie".

Then create a trigger of the type custom event, enable regex matching and enter ".*" (without the quotes).

Click "this trigger fires on some custom events". In the dropdown that appears select your "myCookie" variable, set "equals" as match type and "0" (without quotes) as value.

Use this as exception trigger.

Setting this up as custom event is the easiest way, since this way will the trigger will work on pageload, domReady, click, submit and all other events, standards or custom. Else you would have to set up an exception for every possible GTM event.

like image 8
Eike Pierstorff Avatar answered Oct 20 '22 22:10

Eike Pierstorff