简体   繁体   中英

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.

Simo Ahava declares window.dataLayer before any snippet, and does not clear the ecommerce object

Screenshot of a snippet by Simo, using window.dataLayer and not clearing ecommerce 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. The way google puts it is "to prevent multiple ecommerce events on a page from affecting each other"

Google clears ecommerce object and uses a different syntax

Google's method sounds better to me here, although Simo is arguably the most respected guy in the tracking space.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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