#GTMtips: DataLayer Declaration vs. .Push()
Here’s a tip on how to avoid a horrible, horrible mistake with Google Tag Manager.
Tip 7: Always use .push() with dataLayer
When you assign a value to a variable using the equals ( = ) sign, you are actually reallocating the variable to a new value, and the garbage collection system of the runtime environment sweeps the previous value to bit heaven.
Let’s put it simply: if you redefine dataLayer after the GTM container snippet, you will break GTM’s proprietary functions. No, I’m not trying to be dramatic, it’s the truth. You cause havoc because GTM modifies the native push() method that all Arrays have, adding stuff of little importance such as a listener which fires tags when an ’event’ key is pushed!.