Google Tag Manager Variables for

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 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 GTM Tag.

Data Layer and GTM Variables Tracking Id

Each data packet sent to 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 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 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 NameGTM Variable TypeData Layer Key
Context.AnonymousUserIDData Layer VariableContextAnonymousUserID
  • 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 NameGTM Variable TypeData Layer Key
Customer.CustomAttributesData Layer VariableCustomerCustomAttributes
Customer.EmailAddressData Layer VariableCustomerEmailAddress
Customer.FacebookSlugData Layer VariableCustomerFacebookSlug
Customer.FirstNameData Layer VariableCustomerFirstName
Customer.GDPRDataAnonymizationData Layer VariableCustomerGDPRDataAnonymization
Customer.GDPRMarketingSubscribedData Layer VariableCustomerGDPRMarketingSubscribed
Customer.GDPRRightOfAccessRequestedData Layer VariableCustomerGDPRRightOfAccessRequested
Customer.IdData Layer VariableCustomerId
Customer.InstagramHandleData Layer VariableCustomerInstagramHandle
Customer.LastNameData Layer VariableCustomerLastName
Customer.LinkedInSlugData Layer VariableCustomerLinkedInSlug
Customer.PostalAddressData Layer VariableCustomerPostalAddress
Customer.TwitterHandleData Layer VariableCustomerTwitterHandle

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 NameGTM Variable TypeData Layer Key
Product.AvailableData Layer VariableProductAvailable
Product.CustomAttributesData Layer VariableProductCustomAttributes
Product.FullImageUrlData Layer VariableProductFullImageUrl
Product.IdData Layer VariableProductId
Product.ListPriceExTaxData Layer VariableProductListPriceExTax
Product.ListPriceIncTaxData Layer VariableProductListPriceIncTax
Product.NameData Layer VariableProductName
Product.PrecisData Layer VariableProductPrecis
Product.PriceBreaksDescData Layer VariableProductPriceBreaksDesc
Product.ThumbnailUrlData Layer VariableProductThumbnailUrl
Product.URLData Layer VariableProductURL

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 NameGTM Variable TypeData Layer Key
Order.IdData Layer VariableOrderId
Order.LineItemsData Layer VariableOrderLineItems
Order.TotalOrderValueExTaxData Layer VariableOrderTotalOrderValueExTax
Order.TotalOrderValueIncTaxData Layer VariableOrderTotalOrderValueIncTax
Order.PaymentMethodData Layer VariableOrderPaymentMethod
Order.CurrencyData Layer VariableOrderCurrency
Order.BillingAddressData Layer VariableOrderBillingAddress
Order.DeliveryAddressData Layer VariableOrderDeliveryAddress

The final step is to configure the Tag.

This is described in the next section, Adding the GTM Tag.