The Data Layer

Shivam Chowdhary
5 min readDec 27, 2020

The data layer is a data structure that beholds information about user centric activities and clickstream metrics.

The reason we use a Data Layer is because sometimes it is necessary to decouple semantic information from other information sources.

GTM gives you the flexibility to retrieve information that you want to see and it stores most of this info in the data layer. The data layer is a JSON object that contains native key value pairs and holds beneath objects which are setup in our triggers and tags.

As you can see in the screenshot the kind of actions the admin can track, these get logged into the data layer and then pushed to GA if prescribed to do so.

Pushing info into Data layer

There is a native method that pushes information into the datalayer that goes by dataLayer.push(). There are multiple ways to push this information into the data layer but one can utilise the custom HTML script and redefine dataLayer.push()

The process remains the same, set up a tag then setup configurable triggers associated with the tag and check it in preview mode.

Take the example of setting up a tag using the following process

Now one sets up the trigger associated with tag config and setup a naming convention.

now when one switches over to the data layer, one can see data populating in the preview mode.

Now this is a typical case where one can leverage the custom HTML template to track and read objects into the data layer. The next step would be to push this into GA or some other sink as per requirements.

What happens under the hood when you are a tracking some other event ?

This is what a container snippet looks like and as you can see it tracks user ids, internal user(binary), weather and related events.

The standardised way of using html and custom js with tag manager is to not hard code the snippets but to use the right naming conventions and associated variables such as the one shown in the screenshot. Along with that there are custom events or templates that can be edited or changed, i.e event name.

Now once you have information in the data layer its time to read these details and take relevant actions.

Data Layer Reading details

The way we will discuss this is using data layer variables. Once you have info in the data layer, there is scope of pulling data from this layer by setting up a data layer variable.

The configurations of this data layer variable are simple putting in the same name as the key name on the data layer in our case it is

Once you set up this variable and name it, one can see the same dlv name in the data layer and check when it fires up to debug the process. You can see this in the preview mode in the variables section.

Now fairly simple you have the information in the variable and the inital tag set up that stores info in the Data layer.

Now we setup another tag of an event type that pushes information from this variable to GA and of course the right configuration of trigger when to fire this tag.

Now you don’t want to do this at the first push because one does not have the data layer variable set up then and there but after the character update and variable logging. So therefore you create a new trigger and create a custom event.

Now this custom event will map to the events that have taken place in the data layer and as soon as it spots customevent the new tag will fire and data is in GA !!! Lala !!

TRUST BUT VERIFY

Now you got to GA and check if the variable data pops in there.

Inspector Tool

One of the helpful tools that helps you mirror what is happening with the data layer and how gtm has been structured and the kind of events that are getting captured in their google analytics or some other tool, Once you have this plug in installed you can check out the console this way

This is all for now using the data layer, one can get super technical with cookies and apis on these concepts but yet to learn and so much to learn. Check Mercer’s course on CXL, Phenomenally explained these concepts.

--

--

Shivam Chowdhary

Data Savvy engineer — Exploring Cx as a service for channel optimisation and services. You can find more about me https://www.linkedin.com/in/shivamchowdhary/