In my code every time a page loads, it grabs the departments that page is related to from the WordPress taxonomy and builds an array that is sent to a datalayer variable in tag manager. for example:
in PHP
$department = ["accounting", "sales", "support"];
and in JS
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'department': '<?php echo $department; ?>'
});
in GTM, I want to create a pageview trigger called sales_pageview which fires a tag every time a page loads where "department" contains "sales" and I am not sure how to parse that array in GTM to look for that array element.
Any suggestions anyone? I added some screenshots for reference:
2
Answers
I found the problem with the trigger. After investigating I noticed the value was set to null.
I changed the trigger from pageview to DOM ready and it fired. I guess this was a case where the answer was fairly simple and easy to overlook because I was so focused on the DLV itself.
You can just use
contain
in your triggerHere is the demo example.
I push a datalayer with array
And I set up a trigger use the
datalayer variable
to containtest456
Then it will fire as expected.
Thanks for the a lot of screenshots. They are helping!
The problem becomes very clear now
Your datalayer is pushing a json-encoding object
So the value is
But your trigger is
Finally
So the tag not fired.
Here is the suggestion:
contains
? Or it is not the business rule you want.