Fire Tag after Datalayer Values have changed

余生颓废 提交于 2019-12-02 10:59:29

Yes, you need an event - GTM overwrites the native "push" method on the datalayer array to scan incoming objects for the "event" keyword. Only if the event keyword is present GTM will update its internal state and make the new values available for use in tags and triggers. However you cannot use several events within a single push.

However your first example requires only a single event:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
"Example1": "false",
"Example2": "false",
"Example3": "false",
"Example4": "false",
"Example5": "false",
"event":"examplesHappened"
});

If you insist on splitting this up into several pushes you could use a trigger group - first create a custom event trigger with your "exampleAdded" event, then create a trigger group and add the trigger five times:

Note that you can add a trigger more than once. By adding a trigger more than once into the group, that particular trigger must fire as many times as it has been added to the group for the Trigger Group to work.

(Source)

The downside is that this will only work once per page.

If your pushed are created by some sort of loop you could just the increment to number your events:

for(i=1;i<6;i++) {
 var obj = {};
 obj["example"+i] = "false";
 obj["event"] = "exampleHappened_"+i
 dataLayer.push(obj);
}

and then just fire on the event "exampleHappened5". This would work multiple times.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!