简体   繁体   English

在Google跟踪代码管理器中,dataLayer的顺序是否重要?

[英]Does order of dataLayer matter in Google Tag Manager?

If I create a tag which is triggered on 'page view' in GTM, can I push data to this tag after the tag has been fired? 如果我创建这引发了关于在GTM“网页浏览”标签,我可以把数据传输到标签后,该标签已经被解雇?

This is the event type I'm using (page view) 这是我正在使用的事件类型(页面视图)

<script>
    window.dataLayer = window.dataLayer || []; //dataLayer object is instantiated
</script>

<script>
    var data = {page data, user data etc.}
    dataLayer.push(data);
</script>

<script>
    GoogleTagManager container code
</script>

// Will dataLayer.push(moreData) get caputured in the page view event?

It's my understanding that using dataLayer.push will update the dataLayer on events, however as the pageview event fires on the pageview, it means only information in the dataLayer before the GTM container code is captured in this event. 据我了解,使用dataLayer.push会在事件上更新dataLayer,但是随着pageview事件在页面视图上触发,这意味着仅在此事件中捕获GTM容器代码之前 dataLayer中的信息。

Is this correct, or can I use dataLayer.push to update the pageview information? 这是正确的吗,还是可以使用dataLayer.push更新浏览量信息?

You can always use another trigger, such as gtm.dom or gtm.load to read in any more info that you've pushed in to the dataLayer after the Pageview event has fired. 您始终可以使用其他触发器(例如gtm.domgtm.load来读取触发了Pageview事件后已推送到dataLayer的更多信息。 But I always recommed that you push in an event along with any additional data and use that event to trigger your tag because you may not necessarily want to wait until the DOM has loaded or until the page has entirely loaded. 但是我总是建议您将一个事件与任何其他数据一起推入并使用该事件来触发标签,因为您不一定要等到DOM加载或页面完全加载后再进行操作。

In the example you have provided, Google Tag Manager would likely capture the extra information on DOM ready. 在您提供的示例中,Google跟踪代码管理器可能会捕获有关DOM准备就绪的额外信息。

DataLayer information persists until the page is closed (either new page, or closed page). DataLayer信息将一直保留到页面关闭(新页面或已关闭页面)。 This can make it valuable for tracking information (eg a click value), if you want to collect it at a later time (eg a form submission). 如果您想在以后收集信息(例如表单提交),这对于跟踪信息(例如点击值)很有用。 By firing a dataLayer push on the click (eg did a user click on a store?), that information will be stored within the dataLayer and be ready to be re-called at any time (for that page) like the contact form submission. 通过在点击时触发dataLayer推送(例如,用户是否在商店中点击了?),该信息将存储在dataLayer中,并可以随时(针对该页面)像联系表单提交一样被调用。 This means that you can have an events such as 这意味着您可以发生以下事件

Event Category: Contact
Event Action: Form Submitted
Event Label: Store info interaction | No store info interaction

In addition, it is always best practice to add an event key into each dataLayer push, for example: 此外,最佳做法始终是在每个dataLayer推送中添加事件键,例如:

dataLayer.push({
  'event': 'addToCart',
  'ecommerce': {...
   }
});

It is also worth noting that Enhanced Ecommerce by default reads in the dataLayer in dataLayer version1. 还值得注意的是,默认情况下,增强型电子商务会读取dataLayer版本1中的dataLayer。 This means that only the most recent ecommerce object will be read in. 这意味着将仅读取最新的电子商务对象。

In practice, this means that if you have products and promotions on the same page, and they are sent in different pushes, Google Tag Manager will only collect the most recent push on the initial Pageview. 实际上,这意味着如果您在同一页面上有产品和促销,并且它们以不同的推送方式发送,则Google跟踪代码管理器将仅收集初始页面浏览量中的最新推送。 This is why it is always important to have an event key, as it provides you with some flexibility for firing your tags. 这就是为什么拥有事件键始终很重要的原因,因为它为您提供了触发标记的灵活性。

The "data" in the tag will remain the same, you can't retroactively change the "data." 标记中的“数据”将保持不变,您无法追溯更改“数据”。 When you use GTM preview and debug you see "Page View, "Event," "DOM Ready," etc. When you click on these you can see what the datalayer is for each. You can set your tag to fire at a different time to ensure the information you want is ready to be called. So set up one tag to do the datalayer.push and then another tag to fire with the trigger event equals addToCart rather than pageview. That way the datalayer has all the information you want as it fires after the datalayer.push. 使用GTM预览和调试时,您会看到“页面视图”,“事件”,“ DOM就绪”等。单击这些内容时,您可以看到每个数据层的内容。您可以将代码设置为在其他时间触发为了确保您可以随时调用所需的信息,因此设置一个标签来执行datalayer.push,然后设置另一个要触发事件的标签等于addToCart而不是pageview,这样数据层便拥有了您想要的所有信息它在datalayer.push之后触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM