了解 GTM trigger 的一些重點
- Trigger 的一些重點如下:
- 在設 trigger 前應該先對那些 GTM event 去擊發你的 tag 有些想法.
- trigger type 在概念上結合那些 GTM event(下圖中 gtm.XXX) 與交互動作(下圖中 Page View, Click, User Engagement 所指) (or event) 你想讓 GTM 開始去listening to.
- trigger 重點核心動作:
- triggers require a
dataLayer.push()
or a pre-container-snippet declaration to fire a tag.If apush()
command doesn’t have an ‘event’ key, it becomes merely a “message” that’s added to the message bus. It does nothing for tags.If there’s an ‘event’ key in the message, the instance gets the name of the event (unless it’s one of the three default GTM events, see below) or just “Message” if there’s no ‘event’ key in the command. - if there’s an ‘event’ key in the
push()[當執行此命令]
, a data layer helper object activates and goes through all the active triggers in your container. If any one of these matches the value of the ‘event’ key, and if all the other conditions in the trigger pass, the tag is injected into the site and its code is executed.
- GTM 預設自動觸發的事件: GTM pushes three data layer events into the queue when any page with the container snippet is rendered. They are gtm.js, gtm.load, gtm.dom。gtm.js - This is pushed into the data layer as soon as GTM is initialized and the container is loaded. gtm.dom - When the DOM has been populated with on-page elements, this event is pushed into the data layer. gtm.load - Once the window has finished loading, along with all images, scripts, and other assets, gtm.load is pushed into the data layer.
- Since there’s just one listener controlling the firing of your tags, GTM leverages the
gtm.triggers
key (The value of the key is containerID_triggerID) in the auto-event object to specify which trigger should fire upon the event. - 在click 中的Just link 事件中Check Validation: Only fire tags when the link click is considered a valid action. If unselected, the trigger will fire tags whenever a link is clicked. [也就是這個事件產生傳到 document node 的整個過程必須是完全正確,如果過程中 某 script() 呼叫了 preventDefault(),雖然事件還是會傳到 document node 但是事實上是該正常的 action 沒有正常執行,所以正個過程並不正確。 (在 script 中 use event.preventDefault() to replace return false, preventDefault() also prevents the default action of the link click event, but it doesn’t stop event propagation from continuing up the DOM tree.)
- Click / All Elemenets trigger. Nothing special about that. It just listens to all clicks on your site, regardless of what element you click.
- Just Links triggers require a click on a link, and Form triggers require a valid browser form submit event. Both need propagation to work.
- One important thing to know about triggers and tag sequencing is that if a tag is part of a tag sequence (either as a Setup or Cleanup tag), all its triggers are ignored. tag sequencing trumps triggers. If a tag fires either before or after the main tag in a sequence, it will be completely controlled by the triggers of the main tag. The only way to prevent the tag from firing in a sequence is to pause it.
- 一群 triggers 都曾經觸發過之後才擊發執行 tag: you can add to a tag in Google Tag Manager. It allows you to establish dependencies between multiple triggers, not firing the tag until every trigger in the group has fired at least once.
留言
張貼留言