How to create a Custom Tracker via the DataLayer
Last updated
Was this helpful?
Last updated
Was this helpful?
You can create Custom Trackers directly linked to the DataLayer you have implemented in AB Tasty. These Custom Trackers can then be used to create metrics based on your DataLayer data.
Custom tracker can also be created JavaScript code, for more information, refer to .
To create a Custom Tracker via DataLayer you must:
Declare a DataLayer on this
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 tracker for your DataLayer:
Click Create Custom Tracker on the top right of the table.
Select From a DataLayer.
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:
It can be an item that looks like a JS object with an association of key / value.
To retrieve one key / value association inside this payload, you have to select the object option. (for example, to search the eventCategory)
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:
Deeper with details
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 tracker will be fired when a field, specified by you, matches a certain condition. These are the steps:
Giving the custom tracker 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 tracker. This is mainly for string data types.
Is true
for a boolean value. value is true
Is false
for a boolean value. value is false
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 Tracker: 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 tracker 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 tracker, and reload your tag.
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 tracker 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.
Instead of looking for the value of nested keys, we can have keys using dots (“.”).
For example:
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.
It is possible to have a custom tracker triggered by several conditions being true. Taking the last examples in the previous section, the custom tracker will be triggered if “page.pageType” is equal to “HOME” only. The Custom tracker can also be triggered by BOTH “page.pageType” = “Home” AND “page.device.type” = “mobile”. To do this, create a custom tracker and click on “Add condition”. This will show a second row of inputs to specify another condition.
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 tracker to be triggered. If both are true, it will also be triggered. If none are true, it will not be triggered.
If you select “all”, it means that both (or all, in case there are more than 2) conditions need to be true for the tracker to be triggered. If only 1 is true, the tracker 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:
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:
In this example of a GTM DataLayer, we search these two conditions in all the DL. In this case, the matching is a success.
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:
Once again, once the custom tracker is created and saved, do not forget to refresh your tag.
Once custom trackers 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 Trackers”
In the middle pane, you should see the custom tracker 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 trackers 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.
From the (Library > Tracking > Trackers), go to the Custom Trackers tab.