Understanding the data layer
What is the point of a Data layer and structuring the content of your page in terms of data ?
To be honest with you, it really took me a while to understand what is a data layer. After all, tag management systems have been created in order to get rid of developers, so the big question is why should we care about it and by the way what is a data layer ?
What is a data layer ?
As its name stands for it, a data layer is something which has data within it. The data that it is storing is up to you. So you are the one who is deciding what you will put within it. So let’s say that you would like to store in it the page url, the type of content of the page, the total amount of an order, the number of pets you have at home… this is fine you can insert whatever you want as far as it is data.
Ok but what should I care about the data layer ?
There are several situations in which the data layer will be very helpful. For example, when a data is not on the page but you would like to get this data in order to use it for the tag manager. A typical example is the one of an ecommerce website. You would like to push to the ecommerce tracker code the order id… unfortunately it is listed on the page, so you need to use PHP code or server side code in order to request this data to one of your database, this is where the data layer will be helpful. It will be used to store the data and will make it accessible for your afterwards.
Another use case is for website which are changing a lot what we call the DOM. The DOM is a fancy name to say the content of your pages, it is more related to the structure of your tags. Let’s imagine that tomorrow your developer team update the template of your website. So far you were triggering a lot of tags based on the class, the ids… but in this new template those classes and ids have been removed or their names changed. As a result all your tags are not firing properly. By asking your developer team to implement special attributes within your HTML tags you are making your developers on board and as a result if your triggers are not working anymore, that won’t be 100 % your fault.
So to make it simple a data layer is an extra security you are taking for your project, nothing more. So yes, people are living fine without a data layer, but the chances they have to wake up one day with a bad surprise is higher than the one having a data layer. A data layer is somehow one way to say, « hey at least I gave the best of myself ».
Let’s take two examples
Case number 1 - The data is not listed on the page
Case number 2 - Securing your data with a data layer
As previously mentioned a data layer is here in order to secure that your data will be properly collected. Let’s see one scenario.
I have a page with a button like this one:
My source code is as follow :
So without a data layer, if I wanted to track this click interaction as an event, I will define something like this :
So far, nothing exceptional.
The issue is coming when someone has the good idea to change the text of the click me button. Then your trigger breaks.
To avoid this, developers will implement an event within the HTML tag such as :
Here it means that when someone will click one the button it is going to send an event to the tag manager, so you will need to add a trigger such as this in the tag manager :
which mean that whenever this custom event will be fired then the event will be pushed to my analytics solution.
So as you can read using a data layer is not 100 % compulsory, in IT, there are always millions of ways you can deal with an issue, it is just that here you are transferring your responsibility to someone else. Here you are clearly saying « Hey, I put the developers on board, so if something breaks I am the only one guilty).