Datalayer

Introduction

The datalayer is information provided on the website that let’s us track user interaction. A datalayer consists of:

  1. Events - the interactions a user does
  2. Meta data - the information that tells something about the interaction

An example is that we track when a user has viewed a certain page (event = pageview). In this case the fact that we trigger an event whenever a page is loaded is part of the datalayer. We could then also add information about the page. For example, which domainGroup of pageCategory the page belongs to.

harvest.trackEvent({
    "event": "pageview",
    "data": {
        "domainGroup": "Example sites",
        "pageCategory": "home"
    }
})

For more information about the data model, read our data model documentation.

How to create a datalayer?

The question is, how do create a datalayer. How do you make sure the tracking code is triggered when a user does performs a certain user interaction? And how do you make sure the correct meta data will be sent with the event?

Creating a dataLayer can be done in two ways:

  1. Implementation by a developer
  2. Implementation through DOM scraping

Implementation by a developer

This means that the developer will integrate the tracking code in the application.

Advantages

  • The developer knows exactly when certain actions are performed and can therefore make sure all interactions are tracked correctly.
  • Tracking is not dependent on design of the website. When changes to design are done, tracking will still be in order.
  • Good seperation of responsibilities. The developer is responsible for the technical tracking code, marketers for using the tracked data.

Disadvantages

  • Since developer are required, implementations often take a longer time
  • The developers are usually not educated in how data will be used.

Ultimatily this way of implementing tracking code is the preferable. Tracking code should be incorporated in the development process. A suggestion could be to create some sort of Style and Data guide. This way you not only formalize how certain style elements should be implemented, but also how these elements should be tracked.

Implementation through DOM scraping

This means that the tracking code is not integrated with the application, but tracking code is added client side after the application has rendered. Usually this is done with the use of a tag management solution.

Advantages

  • No dependency on development cycles, which speeds up the process
  • Usually the specialist who is in control of using the data, is also the person who collect it.

Disadvantages

  • Sometimes a certain function, like an add to cart, is used on several places in the website. It is hard to cover everything with DOM scraping
  • Tracking is reliant on HTML, when HTML changes, the tracking breaks
  • Development is not in the loop and this has can result in major problems

DOM scraping is usually quicker, because you do not need development teams. Development processes can be skipped, which can create conflicting code and makes technical problem solving hard.

The best solution is almost always to work together with development and let them do the implementation.

For more information about the tracking code, read our tracking code documentation.