Things that should be taken care of while using data layer:
1. The data layer object name is case-sensitive.
For instance, if you want to push an event or a variable without any proper casing, the push will not work successfully.
So, let’s take a look at an example:
2. The name of a variable must be enclosed in quotes.
For variable names quotes are not required particularly. The quotes can be letters, numbers and underscores, but they can not be reserved words like function, export, native etc.
Therefore, to avoid any issues, it is suggested that all variable names must be enclosed in quotes.
Let’s take a look at an example:
3. The name of a variable must be consistent across pages.
By using different variable names for the same variable on different pages, GTM will not be able to fire tags at all desired locations.
Let’s look at an example:
4. Any information needed to fire tags on a page load must be declared in the data layer above the container snippet.
To understand this better, let’s look at an example:
In order to fire tags on a page load matching some condition (e.g. on pages marked as having a pageCategory of sports), the pageCategory must be defined in the data layer above the container snippet (e.g. ‘pageCategory’: ‘sports’). Variables pushed to the data layer (i.e. using dataLayer.push()) after the container snippet will not be able to fire tags on page loads with a matching condition.