Important dataLayer Notes
How SA5 supports this
In our sa5/gtm-data
construction, you should set all of the properties in the object.
null
values will be converted to undefined
e.g.
Future
Set a default base object, and override it. We merge them
How GTM's dataLayer Works
When you push an object to the dataLayer, GTM doesn't reset or clear previous state between pushes. Instead, properties persist in the dataLayer's state until explicitly overridden or removed. This behavior ensures that data remains available across different events for tags, triggers, and variables to utilize without needing to repush the same information continually.
The Situation with Alpha, Beta, and Gamma
When you push an object containing alpha
, beta
, and gamma
properties to the dataLayer and then subsequently push another object with just alpha
and beta
, the gamma
property remains in the dataLayer's current state. This is why you're seeing gamma
being preserved and appearing as part of the second event, even though you didn't include it in the second push.
How to Prevent Unwanted Properties from Persisting
To prevent properties like gamma
from persisting beyond their intended event, you have a couple of approaches:
Explicitly Set Unwanted Properties to
undefined
ornull
: By explicitly setting properties you want to "remove" toundefined
ornull
in subsequent pushes, you can ensure they don't carry over undesirably.
Last updated