简体   繁体   English

Simo Ahava 还是 Google 文档? 关于 dataLayer.push({ ecommerce: null }); 的问题

[英]Simo Ahava or Google doc? Question on dataLayer.push({ ecommerce: null });

While setting up GTM I came across a crossroad and I don't know which option is best, and why.在设置 GTM 时,我遇到了一个十字路口,我不知道哪个选项最好,也不知道为什么。

Simo Ahava declares window.dataLayer before any snippet, and does not clear the ecommerce object Simo Ahava 在任何片段之前声明 window.dataLayer,并且不清除电子商务 object

Screenshot of a snippet by Simo, using window.dataLayer and not clearing ecommerce object Simo 的片段截图,使用 window.dataLayer 并且不清除电子商务 object

On the other side, Google recommends clearing the ecommerce object before any ecommerce event to prevent any potential issues with variables using datalayer v1.另一方面,Google 建议在任何电子商务事件之前清除电子商务 object,以防止使用数据层 v1 的变量出现任何潜在问题。 The way google puts it is "to prevent multiple ecommerce events on a page from affecting each other" google的说法是“防止一个页面上的多个电商事件相互影响”

Google clears ecommerce object and uses a different syntax谷歌清除电子商务 object 并使用不同的语法

Google's method sounds better to me here, although Simo is arguably the most respected guy in the tracking space. Google 的方法在这里对我来说听起来更好,尽管 Simo 可以说是跟踪领域最受尊敬的人。

So which method is the best, and why?那么哪种方法最好,为什么?

I do not think these two snippets cover the same use cases.我不认为这两个片段涵盖相同的用例。 Simo talks about initializing the datalayer (usually before the GTM snippet, there would be little point in doing this afterwards), the second snippet assumes that the dataLayer object already exists. Simo 谈到初始化数据层(通常在 GTM 代码片段之前,之后这样做没有什么意义),第二个代码片段假设数据层 object 已经存在。

So this is not "one or the other", but ideally you do both - setting up the dataLayer before the GTM snippet, but also clearing the e-commerce object between two unrelated e-commerce pushes.因此,这不是“一个或另一个”,但理想情况下,您可以同时执行这两项操作——在 GTM 片段之前设置数据层,同时清除两个不相关的电子商务推送之间的电子商务 object。

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

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