Why a data layer will help your website analytics

Adding a data layer to your website will help you better understand your users behaviour.

Not only does it improve the information you collect it’s relatively quick to implement and easy to maintain.

When I first came across the term data layer it sounded like a scary complicated thing to implement – it’s not.

How a data layer works

The data layer is just a JavaScript object which goes in the <head> of every web page – it looks something like this.

    dataLayer = [{
        'productPrice': '7.99'	

You use a data layer to add information about the user and the page content, such as product price, blog category, user preference and so on. Basically anything you think would be useful to collect for your web analytics

A data layer by itself doesn’t do anything. You need to pass this information to your web analytics provider like Google Analytics. To pass this information the easiest way is to use a tag manager like Ensighten or Google tag manager to read the data layer.

All of this requires a bit of technical set up by a developer. The time it takes to do this initial setup is perhaps the only real downside of a data layer.

Benefits of the data layer

A data layer gives you flexibility, control and predictability over how you collect data. It’s also easy to maintain compared to adding tracking IDs within a page.

For example if you had a recipe website the data layer for a recipe page could look something like this:

    dataLayer = [{
        'vistorType': 'Signed in',
        ‘visitorGender’: ’Male’, 
        'readyIn': '01:34',	
        'recipeVideo': 'Yes',
        'course': 'Main',
        'dietary': 'Vegetarian',
        ‘mainIngredient’: ‘Potato’		

You might want to know if recipes which take a short time are more popular on your website compared to recipes which take a long time.

Without a data layer it would be very tricky to find out an answer. Google Analytics for example would be able to tell you which are the most popular recipes but it wouldn’t tell you how long those recipes take to make.

You could get a tag manager to scrape your site to look for the div id with the ready in time. However if a developer decided to change the id or structure of how the time is displayed it would break your analytics.

The benefit of the data layer is it separates the code required to display content to your user and the code required for your analytics. One can be edited without impacting the other.

Choosing the right data layer

Once you’ve decided a data layer is a good idea the question is which data layer do you use.

There are a few options but personally I’m only familiar with two.

W3C’s version CEDDL was developed so you could use it with multiple 3rd party providers. It was created to stop the need for vendor-specific format requirements. Which means you are free to change suppliers with little development time.

Google’s datalayer is used in conjunction with Google’s tag manager. Compared to CEDDL it has better documentation and tutorials. The main downside is you are locked into Google’s ecosystem.


Adding a data layer to your website is a simple way to get more data about your users behaviour. The only limitations are development time and your responsibilities to the end user – never include PII (personally identifiable information).

However, adding a data layer is just the first step. You need to use the data layer with a tag manager, which in turn passes it to your analytics.

Once your data is in something like Google Analytics the real work starts. A data layer helps get the data in a better structure to make it easier to analyse. What is doesn’t do is analysis the data – that’s up to you.

You can see how Google’s datalayer might be implemented with this chrome plugin called datalayer-checker.

As the name suggests it checks if it can detect Google’s datalayer format. Unfortunately I’ve not found a similar product for checking CEDDL.

Once you have the plugin installed you can then check my site or Google’s example ecommerce site to see a data layer in action.

Screenshot of the datalayer-checker plugin in action

Note: When I first came across a data layer I thought it could be integrated with Google’s structured data. They both seemed to be solving similar problem – providing information about a page for a service to consume. But I quickly realised Google’s schema is doing a separate job for SEO (search engine optimisation) and should be separate.

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts