All Collections
Campaign Analytics
Tracking user behavior via DataLayer Events
Tracking user behavior via DataLayer Events

Track user behavior in your campaign with Google Tag Manager dataLayer

Anders Lund avatar
Written by Anders Lund
Updated over a week ago

Are you looking to improve your data collection process and better understand your users' experiences? On all Playable campaigns, we have implemented a datalayer with various data points that can help monitor user behavior in the campaign flow.

'dataLayer' is a JavaScript object often used in the context of web analytics and tracking on websites. You can use dataLayer to feed information about user interactions and events from your campaigns to Google Tag Manager (GTM).

We push information about 4 different events to the dataLayer. Each event is triggered based on specific data conditions and provides details about how users behave during the game flow.

The information made available in the datalayer can be transferred and managed in GTM.

In this article, we will:

  • Introduce the four events we make available in the datalayer

  • Provide examples of the use of dataLayer tracking in practice

  • Take you through the steps of setting up a dataLayer-based event in GTM

The 4 events

Below you will find an overview of the four different events that we push to the dataLayer.

User behavior

Example of event

Button click

“Playable_button_click”

pageId: 777777

buttonText “Start Game”

pageTitle: “Presentation Page”

Flow page change (current flow page title)

“Playable_flow_page”

pageId: 777778

pageTitle: “Game”

Game page change

For quiz & personality test

“Playable_game_page”

questionIndex: 1

Registration limit

“Playable-registration_limit”

pageId: 777779

pageTitle: “Page Limit”

Examples: Use of DataLayer in practice

Example 1: Track behavior in the game flow

The first example takes point of departure in the following scenario:

You have built a “level quiz” with over 20 questions and you want to get insights into when in the quiz users are dropping off, either because they were not engaged or because the quiz was too difficult.

To gain more knowledge about the user behavior in the quiz, we can track the following events:

  • The event “questionIndex” will tell us where in the quiz the user dropped off. The platform will push an event for each step in the quiz.

  • If a player answers a question incorrectly in a level quiz, they will be directed to the loser page. The event “pageTitle” can tell us if a user landed on the loser page.

Based on this data, you can analyze where and why users are failing in your flow and make necessary improvements to enhance their experience.

In this section, you can read more about how to collect this information in GTM.

Example 2: Registration limit reached

Per default, the 'registration limit' message is not included in the funnel statistics. This means that we have limited insights into, how many participants reach the registration limit.

Via the event “Playable-registration_limit” we can gain insights into how many participants try to register, but see the registration limit page.

Based on this data, you can assess whether the registration limit should be modified.

How to Set Up Variables and Triggers in GTM for Data Collection

In this section, we will walk you through the steps you will need to take to transfer relevant data points from the dataLayer into GTM.

Components in GTM

A Google Tag Manager is based on three essential components: Variables, Triggers, and Tags.

Tags:

  • Tags represent the desired action you want to track. For example, you may want your tag to activate an event

Triggers:

  • Triggers are the conditions that activate the tags. In the previous examples, we would trigger a tag when a user reaches the registration limit message.

Variables:

  • A variable is a placeholder that helps retrieve information when code is run on a website. When we track by using dataLayer, we use the variable to read event information pushed by the platform.

Stepguide to transferring information from dataLayer to GTM

Step 1: Create a Variable

When tracking through dataLayer, we need to create variables in GTM that can help us retrieve relevant data.

Variables can be used in combination with different triggers and tags. For example, the variable "pageTitle" can collect data about several flow pages, however, you can activate different triggers and tags based on the same variable.

If you are collecting data via dataLayer across campaigns, it will be sufficient to set the variable up once!

How to add the variable in GTM

1. Navigate to Variables. Within the user-defined Variables, click 'New Variable'. From the page variables, choose 'Data Layer Variable'.

2. Enter the name of the variable. In this example, we want to track how many participants land on the registration limit page, so we use the variable name 'pageTitle'.

User behavior

Example of event sent

Registration limit

pageTitle: “Page Limit”

Save the variable.

Now, the variable is set up to scan for the event information 'pageTitle', which we will use in our trigger.

Step 2: Create a Trigger

1. Create a trigger, select 'Custom Event' and fill in the event name

2. Hereafter, you need to decide when the trigger should fire. You do this by selecting. 'Some Events'. This will allow you to set up the conditions for your trigger.

In the dropdown, choose the variable created in step 1 and set it to = the title of the game page you want to track, in this case the Page Limit. It could also have been 'winner page' 'loser page' or whatever name you gave your flowpage.

User behavior

Example of event sent

Registration limit

pageTitle: “Page Limit”

Step 3: Create a Tag

Now that we have the trigger and variable, let's create the tag that will facilitate the transmission of data to third-party services.

Create a tag as usual and select the configuration you want to use for the tag. The configuration will depend on the action you wish to activate with the tag.

After setting up the tag configuration, you must select the trigger from step 2:

By following these steps, you've successfully collected and transferred information from the dataLayer to GTM. With this configuration, GTM tracks the event and ensures that a GA4 event is sent when a user lands on the 'registration limit page'.


Working with dataLayer and Google Tag Manager can be a complex task, so if our guide has left you with any unanswered questions, please reach out to our chat support :-)

Search terms: dataLayer, tracking, track, behavior, events, event, GTM, 

Did this answer your question?