Google Tag Manager Variables for Distil.ai
In the Introduction to the Google Tag Manager section we highlighted resources provided by Google that describe the concepts behind Google Tag Manager (GTM). We linked to the GTM developer documentation that describes how to install the GTM Code and how to setup Data Layer Variables. And then, in the previous section, we setup our Google Tag Manager (GTM) account and tested that it was working.
The Types of Event Data document lists the data that we need to pass through to Distil.ai. These are Context, Customers, Products and Orders. This next section defines the Key/Value pairs that need to be added to the GTM Data Layer in your code and how to configure their corresponding Variables in the GTM Interface. Once we have done this, the next section details how to setup the Distil.ai GTM Tag.
Data Layer and GTM Variables
Distil.ai Tracking Id
Each data packet sent to Distil.ai requires the Distil Tracking Account Id. This is used to route the Event stream to the correct account. This does not change and so it can be setup in GTM as a Constant Variable.
Note: To get your Distil Tracking Account Id please contact your Supported Onboarding representative.
In the GTM User Interface select the Variables section. Click New. From the resulting screen pick the Constant variable from the list of variables types.

Next, set the constant value to that of your Distil.ai Tracking ID. Give the variable a name of Distil.TrackingId. This is shown in the screen below:

Click Save. Thats it. We have now defined a Variable that contains your Distil Tracking Id that can be passed to any Tags that we setup in GTM.
Adding variables to GTM in this manner is carried on throughout the rest of this document. However all the other Variables that we add will be Data Layer Variables, not Constant Variables. A Data Layer Variable in GTM defines the Variable name in GTM and the corresponding Data Layer Key. If a key is found in the DataLayer JavaScript Object that matches a GTM Variable, its value will be picked up.
Context Variables
Next is to add the Variables for data attributes as described in the Context Event data section. This data packet contains values that describe the context of each event. The Browser, Timestamp, Page Title, URL and so on. Most of these attributes can be pulled from the DOM by the Distil.ai GTM Tag. As the Distil Tracking ID value was created in the previous section the only variable we need to add to complete the context data is the Anonymous User ID.
The table below shows the configuration to be deployed.
GTM Variable Name | GTM Variable Type | Data Layer Key |
Context.AnonymousUserID | Data Layer Variable | ContextAnonymousUserID |
- Firstly, a Data Layer Variable needs to be defined in your code called ContextAnonymousUserID. This should be added as per the specification described in Tracking – Context. The Context.AnonymousUserID value should be added to the Data Layer on all pages.
- Secondly, a GTM Variable should be added that connects the Data Layer Variable to a GTM Variable. The GTM Variable should be called Context.AnonymousUserID and be defined as a Data Layer Variable.
The following describes how to do this final step in GTM. This sequence of steps can be repeated for all other Data Layer Variables defined in this section.
Adding Data Layer Variables to GTM
1. Browse to the Variables section of Google Tag Manager.
2. Select New to create a new Variable.
3. Enter the name of the GTM Variable as defined in the table above. In this case Context.AnonymousUserID.

4. From the Choose variable type picker select Data Layer Variable.

5. Enter the Data Layer Key as defined in the table into the Data Layer Variable Name box. In this case ContextAnonymousUserID.
6. Click Save.

Google Tag Manager will now inspect your code and look for a key named ContextAnonymousUserID in a JavaScript Object called dataLayer
. If found it will be assigned to the Context.AnonymousUserID GTM Variable. This can now be passed into any Tag that needs this data.
This process should be repeated for all the variables defined in the sections below. Once done your GTM Interface will look something like this:

Customer Variables
The following table describes the Data Layer and GTM Variables for when a known Customer is active. This is taken from the Tracking -Customer document.
GTM Variable Name | GTM Variable Type | Data Layer Key |
Customer.CustomAttributes | Data Layer Variable | CustomerCustomAttributes |
Customer.EmailAddress | Data Layer Variable | CustomerEmailAddress |
Customer.FacebookSlug | Data Layer Variable | CustomerFacebookSlug |
Customer.FirstName | Data Layer Variable | CustomerFirstName |
Customer.GDPRDataAnonymization | Data Layer Variable | CustomerGDPRDataAnonymization |
Customer.GDPRMarketingSubscribed | Data Layer Variable | CustomerGDPRMarketingSubscribed |
Customer.GDPRRightOfAccessRequested | Data Layer Variable | CustomerGDPRRightOfAccessRequested |
Customer.Id | Data Layer Variable | CustomerId |
Customer.InstagramHandle | Data Layer Variable | CustomerInstagramHandle |
Customer.LastName | Data Layer Variable | CustomerLastName |
Customer.LinkedInSlug | Data Layer Variable | CustomerLinkedInSlug |
Customer.PostalAddress | Data Layer Variable | CustomerPostalAddress |
Customer.TwitterHandle | Data Layer Variable | CustomerTwitterHandle |
Product Variables
The following table describes the Data Layer and GTM Variables to be setup when a known Product is being viewed. This is taken from the Tracking – Product document.
GTM Variable Name | GTM Variable Type | Data Layer Key |
Product.Available | Data Layer Variable | ProductAvailable |
Product.CustomAttributes | Data Layer Variable | ProductCustomAttributes |
Product.FullImageUrl | Data Layer Variable | ProductFullImageUrl |
Product.Id | Data Layer Variable | ProductId |
Product.ListPriceExTax | Data Layer Variable | ProductListPriceExTax |
Product.ListPriceIncTax | Data Layer Variable | ProductListPriceIncTax |
Product.Name | Data Layer Variable | ProductName |
Product.Precis | Data Layer Variable | ProductPrecis |
Product.PriceBreaksDesc | Data Layer Variable | ProductPriceBreaksDesc |
Product.ThumbnailUrl | Data Layer Variable | ProductThumbnailUrl |
Product.URL | Data Layer Variable | ProductURL |
Order Variables
The following table describes the Data Layer and GTM Variables to be setup when an Order has been placed. This is taken from the Tracking – Order document.
GTM Variable Name | GTM Variable Type | Data Layer Key |
Order.Id | Data Layer Variable | OrderId |
Order.LineItems | Data Layer Variable | OrderLineItems |
Order.TotalOrderValueExTax | Data Layer Variable | OrderTotalOrderValueExTax |
Order.TotalOrderValueIncTax | Data Layer Variable | OrderTotalOrderValueIncTax |
Order.PaymentMethod | Data Layer Variable | OrderPaymentMethod |
Order.Currency | Data Layer Variable | OrderCurrency |
Order.BillingAddress | Data Layer Variable | OrderBillingAddress |
Order.DeliveryAddress | Data Layer Variable | OrderDeliveryAddress |
The final step is to configure the Distil.ai Tag.
This is described in the next section, Adding the Distil.ai GTM Tag.