You can create Custom Trackings directly linked to the DataLayer you have implemented in AB Tasty. These Custom Trackings can then be used to create metrics based on your DataLayer data.
Requirements
To create a Custom Tracking via DataLayer you must:
- Declare a DataLayer on this page
The available DataLayer are the following:
- Google Tag Manager
- Tealium
- Commander Act
We don’t manage the custom dataLayer as we can’t predict its structure.
To create a custom tracking for your DataLayer:
- From the Indicators page (Library > Tracking > Indicators), go to the Custom Tracking tab.
- Click Create Custom Tracking on the top right of the table.
- Select From a DataLayer.
Tracking the value of a key in your DataLayer
Structure of the DalaLayer items
Each dataLayer has their own structure.
Let’s focus on Google Tag Manager. Inside GTM, the items belonging to the DataLayer have 2 different structures:
Objects
It can be an item that looks like a JS object with an association of key / value.
{
"event": "nameEvent",
"eventCategory": "nameCategory",
"eventAction": "nameAction",
"gtm.uniqueEventId": 332
}
To retrieve one key / value association inside this payload, you have to select the object option. (for example, to search the eventCategory)
“Arrays” (specific to GTM)
Or, we could have other items with a different structure. We call them array items (FYI, it’s not a real JS array). But, we have some items with this structure:
[
.....
13: Arguments(3) : ['event', 'nameEvent', { payload here}],
....
]
Deeper with details
{
"0": "event",
"1": "abtasty",
"2": {
"abtasty_campaign": "[campaignId] campagnName",
"abtasty_variation": "[variationId] variationName",
"send_to": "XXX",
"exp_variant_string": "value variant string"
}
}
Here, we have different indexes. The index 0 is relative to one event (string), the second one to another string (name of the event) and the third (last) one to a payload. This structure is not a structure by default. You can have another structure (payload inside item 1 for example).
To look for the abtasty_campaign for example, you have to choose the array option and provide on which index we have to research.
We are not able to research a string inside an array (as a value). For example, searching for the index 1 with the value abtasty is not possible. The payload linked to the dedicated index has to be a JS object.
The custom tracking will be fired when a field, specified by you, matches a certain condition. These are the steps:
- Giving the custom tracking variable a name. This name can be anything you choose and only aims at helping you recognize what you create.
- The “key” is the name of the field you want to track in your DataLayer
- The dropdown menu contains a list of operators that allows you to check for the state or value of the field in the DataLayer. The list of operators:
Operator | Description |
Equals | Real key value = Target value |
Does not equal | Real key value ≠ Target value |
Is lower than | Real key value < Target value. This has to be a numerical value. |
Is higher than | Real key value > Target value. This has to be a numerical value. |
Is included between | Upper Target value > Real key value > Lower Target value. These have to be numerical values. |
Contains | Example: the value “homeowner” contains “meow”. That will trigger the tracking. This is mainly for string data types. |
Is declared | The key exists in the DataLayer. This does not need a value. |
Is not declared | The key does not exist in the DataLayer. This does not need a value |
- Select the value of the key that would trigger the Custom Tracking:
Each time the value will match your rule, an event will be fired via our tag Datacollect.
An example is given in the image below:
It means that, once saved, the custom tracking will be triggered when the DataLayer has a field “event” having a value of exactly “gtm.load”.
The final steps are to Save the custom tracking, and reload your tag.
Managing the dot (“.) inside a key
Tracking the value of nested keys in your DataLayer
The DataLayer typically will not have a single level of key:value pairs. It may have nested keys, like in a typical object.
In the previous section, the key:value pair was a first level pair.
You may want to track a 2nd level or even 3rd level key:value pair, like in the image below:
To track nested keys like “pagetype” or “type”, the key field in the custom tracking creation modal can be input with dots (.) as shown:
- page.pageType - this will have a value of “HOME”
- page.device.type - this will have a value of “mobile”
Arrays are not handled in the DataLayer for the moment, but only objects and subobjects.
Tracking a key with a dot inside
Instead of looking for the value of nested keys, we can have keys using dots (“.”).
For example:
{
"gtm.start": 1714033074154,
"event": "gtm.js",
"gtm.uniqueEventId": 1
}
To search the gtm.uniqueEventId, you must use double quotes in order to specify that the key has a dot (“.”) and that you don’t want to track a value of a nested key.
Tracking a combination of key:value pairs
It is possible to have a custom tracking triggered by several conditions being true. Taking the last examples in the previous section, the custom tracking will be triggered if “page.pageType” is equal to “HOME” only.
The Custom tracking can also be triggered by BOTH “page.pageType” = “Home” AND “page.device.type” = “mobile”. To do this, create a custom tracking and click on “Add condition”. This will show a second row of inputs to specify another condition.
Option Some
As soon as you have at least 2 conditions, a new dropdown appears. The first option is “some”. It means that at least 1 condition needs to be true for the tracking to be triggered. If both are true, it will also be triggered. If none are true, it will not be triggered.
Option All
If you select “all”, it means that both (or all, in case there are more than 2) conditions need to be true for the tracking to be triggered. If only 1 is true, the tracking will not be triggered. If none are true, it will also not be triggered.
When selecting the “all” option, you can choose between two other options:
In any Event of the Datalayer : (Only for GTM)
It means that you can check if there’s a matching of all the conditions in all the items of the DataLayer. For example, a DataLayer with this structure:
[
......
{
event: "page_view"
page: {
pageType: "HOME"
}
},
...,
{
event: "device"
page: {
device: {
type: "mobile"
}
}
}
]
In this example of a GTM DataLayer, we search these two conditions in all the DL. In this case, the matching is a success.
In the same event : (Only for GTM)
If you select this option (for the “all” option), all the conditions must be in the same event. If it’s not the case, we don’t parse the other items belonging to the DL (instead of the other option). That’s why in the previous example, the dataLayer must be like this:
[
....
{
page:
{
pageType: 'HOME'
device:
{
type: "mobile"
}
}
}
....
]
Once again, once the custom tracking is created and saved, do not forget to refresh your tag.
Using the custom tracking
Once custom trackings are created, they can be used as goals for your reporting. To include them in your Reportings:
- Go to the goal step of your campaign
- Choose “Custom Trackings”
- In the middle pane, you should see the custom tracking you created with the name you gave them (see first section)
- You can then drag and drop them as primary or secondary goals from here.
- Save.
The DataLayer is a global array which is displayed when one website is also loaded. When a user makes any action on the website, some new items could be pushed inside this array. That’s why the DataLayer could grow up. Once you’ve finished setting up one or several custom trackings on app2, we are able to detect if the association key:value is already inside the DataLayer or if it is inside a new pushed item.