skip to Main Content

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:

tag config
trigger config
variable config
datalayer push code
GTM Assistant Output 1
GTM Assistant Output 2
GTM Assistant Output 3
GTM Assistant Output 4
Dev Console Messages

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. You can just use contain in your trigger

    Here is the demo example.

    I push a datalayer with array

    enter image description here

    And I set up a trigger use the datalayer variable to contain test456

    enter image description here

    enter image description here

    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

    enter image description here

    So the value is

    '["public-works", "human-resource"]'
    

    But your trigger is

    enter image description here

    equals human-resource
    

    Finally

    '["public-works", "human-resource"]'
    
    is not equal to
    
    human-resource
    

    So the tag not fired.

    Here is the suggestion:

    1. Check the datlayer value is matching your expecting or not. If not then change it.
    2. Is the trigger can change to contains ? Or it is not the business rule you want.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search