Skip to main content

Google Tag Manager Integration for Advertisers

This page explains how to implement Rokt Ads with Google Tag Manager to close the loop by linking conversions back to your campaigns. By linking conversions back to your Ads engagement, you can enable more accurate attribution, real-time optimization, and campaign measurement.

You'll learn how to:

  • Create GTM variables that read values from your site's data layer
  • Create GTM tags to initialize the Rokt SDK, identify users, and log conversion events

Before you start

Make sure you have:

  • Access to the correct Google Tag Manager container for your site
  • A data layer already implemented on your site (typically done by your developers)
  • Your Rokt API key (provided by your Rokt account manager)

Understanding the data layer

Your developers should implement the data layer on your site.

A data layer is an object that contains all of the information that you want to share with Google Tag Manager (GTM). Information such as events or variables can be shared to Google Tag Manager via the data layer, and triggers can be set up in Google Tag Manager based on the values of variables (e.g., fire a remarketing tag when purchase_total > $100) or based on the specific events. Variable values can also be shared through to other tags (e.g., add purchase_total into the value field of a tag).

Refer to Google's GTM developer guide for comprehensive details on how the data layer works.

Example of a data layer:

window.dataLayer = window.dataLayer || [];

window.dataLayer.push({
email: "jenny.smith@rokt.com",
user: {
firstname: "Jenny",
lastname: "Smith",
},
ecommerce: {
transaction: {
amount: "12.36",
},
},
event: "gtm.transactionComplete",
});

Identify your variable names

Variables are set up in your GTM account and are matched to the data layer. Refer to the GTM developer guide for more details about variables.

The structure of your data layer on your page affects the data layer variable name in your GTM.

Example data layer script 1:

window.dataLayer.push({
email: "jenny.smith@rokt.com",
});

Data layer variable name: email

Example data layer script 2:

window.dataLayer.push({
user: {
firstname: "Jenny",
},
});

Data layer variable name: user.firstname

Example data layer script 3:

window.dataLayer.push({
ecommerce: {
transaction: {
amount: "12.36",
},
},
});

Data layer variable name: ecommerce.transaction.amount

Create your variables in Google Tag Manager

  1. Log in to your Google Tag Manager container.
  2. Click Variables.
  3. Under User-defined variables, click New.
  4. Enter a name for your variable.
  5. Click Choose a variable type to begin setup...
  6. Under Page Variables select Data Layer Variable.
  7. Enter the Data Layer Variable Name. See the examples above to identify the variable name based on your data layer structure.
  8. Click Save.

Rokt recommends creating variables for the attributes you plan to send to Rokt, such as:

  • email
  • firstname
  • lastname
  • mobile
  • conversiontype
  • confirmationref
  • billingzipcode
  • amount
  • paymenttype
  • country
  • language
  • currency

Configure the Initialization and Log Page Views Tag

The mParticle by Rokt - Initialization and Log Page View tag can:

  • Initialize the Rokt SDK
  • Log page views

Use these steps to create the Initialization and Log Page Views tag:

  1. Click Tags in the left-hand navigation from your container and click New. Google Tag Manager
  2. Select Tag Configuration.
  3. Select Discover more tag types in the Community Template Gallery. Google Tag Manager
  4. Search for Rokt and select mParticle by Rokt - Initialization and Log Page View. Google Tag Manager
  5. Enter a descriptive name for your tag (for example, [Rokt] Initialize and Log Page Views).
  6. Enter configuration settings:
    • API Key: Enter your Rokt API key (this is provided by your Rokt account manager).
    • Development Mode: If you are testing your integration, check the Development Mode box. If you are ready to use your tag for production, uncheck this box.
    • Log Page Views: Logging page views records a page view event (with attributes like screen_name, url, and referring-page) as soon as each page loads.
      • Your page view event attributes will correspond to attributes on your site (for example, if you are on the "payment" screen, your screen_name will be payment).
      • You should log page views as soon as each page in the user's transaction journey is loaded.
    • Log Level: In the dropdown, select your preferred level of logging (Verbose, Warning, None).
    • Disallow Functional Cookies: Functional cookies are used to enhance the usability and performance of a site or an app. For more details, see cookie preferences.
    • Disallow Targeting Cookies: Targeting cookies are used to enable advertising, retargeting, and marketing personalization. For more details, see cookie preferences.
    • Use Cookie Storage: Cookie storage for an SDK integration is used to persist key values (such as identifiers or consent state) so the SDK can maintain continuity across pages and sessions.

Google Tag Manager

  1. Configure the trigger for this GTM tag. The next steps vary depending on whether your site is a multipage application (MPA) or a single-page application (SPA):
  • Trigger configuration for multipage applications
    1. Select All Pages from the list.
  • Trigger configuration for single page applications
    1. Select All Pages and History Change from the list.
note

The Initialization & Log Page View tag should be loaded on all pages. The exact trigger configuration may vary depending on your implementation. If you have questions about the implementation strategy, reach out to your Rokt account manager.

  1. Enter a descriptive name for your trigger, like All Pages or History Change.
  2. Add exceptions if necessary.
  3. Click Save.
note

As part of the Initialization & Log Page View tag execution, a custom event roktInitComplete will be pushed to the data layer when initialization completes. It is highly recommended to use a GTM Custom Event trigger with event name roktInitComplete for subsequent mParticle by Rokt - Events tags.

Configure the Events Tag

The mParticle by Rokt - Events tag can:

  • Identify users
  • Log conversion events
  • Send user and event attributes to Rokt

Although you can enable multiple actions in a single Events tag, some implementations require one GTM tag per action (for example, one tag for Identity and one tag for Log Event). If you have questions about the implementation strategy, reach out to your Rokt account manager.

caution

Ensure the Initialization & Log Page View tag runs before any Events tags. Use the roktInitComplete data layer event in your triggers so Events tags fire only after initialization.

Use these steps each time you create a new Events tag (for example, one for Identity and one for Log Event):

  1. Click Tags in the left-hand navigation from your container and click New. Google Tag Manager
  2. Select Tag Configuration.
  3. Select Discover more tag types in the Community Template Gallery. Google Tag Manager
  4. Search for Rokt and select mParticle by Rokt - Events. Google Tag Manager
  5. Enter a descriptive name for your tag (for example, [Rokt] Identify user, [Rokt] Log conversion).
note

You can enable one or more actions in a single Events tag (Identity, Log Event, and/or Select Placements). Configure all the actions you want for this tag instance first, then click Save when you are finished.

If you need the tag to fire multiple times (for example, once to identify a user and later to log an event), create multiple GTM tags using the same Events template.

Identify the User

Rokt recommends identifying the current user (for example, by email) so conversion events can be attributed correctly. Configure this tag to fire as soon as the user's email is available in your data layer.

  1. In the mParticle by Rokt - Events tag, navigate to the Identity section and select Enable Identity.
  2. Under the IDSync Method dropdown, select Identify.
  3. Under Identity Type, click Add Row and select your desired identity type:
    • If you are sending a raw email address, select Email from the Key dropdown and enter your GTM variable for raw email. Google Tag Manager
    • If you are sending a hashed email value, select Other from the Key dropdown and enter your GTM variable for hashed email. Google Tag Manager
  4. (Optional) Select Hash Raw Email? if you want the tag to hash the raw email value before it is sent to Rokt. Google Tag Manager
  5. Configure Triggering so the tag fires only after initialization and only when the email value is available.
    • Example (email is already present on a checkout page load):
      1. In Triggering, click + to create a new trigger.
      2. Under Trigger Configuration, select Custom Event.
      3. Set Event name to roktInitComplete.
      4. Set the trigger to fire on Some Custom Events.
      5. Add conditions that match your implementation, for example:
        • Page URL contains checkout
        • {{User Email}} matches RegEx .+@.+\..+
      6. Click Save to save the trigger.

Google Tag Manager 6. When you are done adding actions to this Events tag, click Save.

Log a Conversion Event

The Log Event action sends conversion events to Rokt. Configure this tag to fire on the page (or event) that happens after a conversion, such as a purchase confirmation or "thank you" page.

  1. In the mParticle by Rokt - Events tag, navigate to the Log Event section and select Enable Log Event.
  2. Under Configuration, enter conversion as the Event Name and select Transaction as the Event Type.
  3. (Optional) Add any custom flags you need under Custom Flags.
    • A custom flag is a key/value pair containing information about the page/event, usually specific to a technology partner (for example, SnapchatConversions.ClickId). Custom flags are sent only to the specific partner they are intended for, unlike custom attributes.

Google Tag Manager 4. Configure the trigger for this GTM tag. The next steps vary depending on whether your site is a multipage application (MPA) or a single page application (SPA):

  • Trigger configuration for multipage applications
    1. Select Custom Event from the list.
    2. Enter roktInitComplete as the event name.
    3. Change the trigger firing rules to Some Custom Events.
    4. Enter the URL parameter(s) that identify each unique page where the tag should fire. For example, if your confirmation page is example.com/cart/payment/confirmation, the identifying parameter can be any of cart, payment, or confirmation.

Google Tag Manager

  • Trigger configuration for single page applications
    1. Select History Change from the list.
    2. Change the trigger firing rules to Some History Changes.
    3. Enter the URL parameter that identifies the page where the tag should fire. For example, if your confirmation page is example.com/cart/payment/confirmation, the identifying parameter can be any of cart, payment, or confirmation.
  1. Click Save to save the trigger.
  2. When you are done adding actions to this Events tag, click Save.

Adding Attributes

Along with identifying a user and logging conversion events, Rokt recommends sending additional attributes to improve campaign optimization.

  1. In the mParticle by Rokt - Events tag, navigate to the Attributes section.
  2. Enter as many attributes as you have available that are related to the user or event. For predefined attributes, Rokt will automatically categorize them as a user attribute or an event attribute, as shown below.

Google Tag Manager

Predefined Attributes

Attribute KeyExample ValueUser AttributeNotes
First NameJohnThe customer's first name.
Last NameDoeThe customer's last name.
Mobile3125551515Phone numbers can be formatted either as 1112345678 or +1 (222) 345-6789.
Age33The customer's age.
Date of Birth19900717Date of birth. Formatted as yyyymmdd.
GenderMThe customer's gender. For example, M, Male, F, or Female.
Payment TypeCredit CardPayment method used for the transaction. For example, Credit Card, PayPal, Apple Pay.
Confirmation Reference/Transaction IDORD-123456Unique transaction or confirmation reference ID for the purchase.
Amount52.25The total transaction amount.
Conversion TypePurchaseType of conversion event. For example, Purchase, Signup, Lead.
Passback Conversion Tracking IDTRACK-789Rokt Click ID.
Address Line 1123 Main StreetThe customer's primary address line.
Address Line 2Apt 4BThe customer's secondary address line (apartment, suite, etc.).
CityBrooklynThe customer's city.
StateNYThe customer's state or province.
ZIP Code11201The customer's ZIP or postal code.
CountryUSThe customer's country.
TitleMrThe customer's title. For example, Mr, Mrs, Ms, Dr.
LanguageenLanguage associated with the customer or purchase.
note

The Conversion Type and Confirmation Reference/Transaction ID attributes allow Rokt to optimize your campaign effectively and deduplicate events and conversions appropriately. These are required launch attributes.

Please confirm the attributes with your Rokt account manager before you complete the integration.

  1. If there are additional attributes you want to send that aren't already defined, click Add Row under Custom Attributes.
  2. Enter the attribute name and value under Attribute Name and Attribute Value.
  3. If the attribute is related to the user (not the conversion event), select User Attribute. Google Tag Manager
  4. When you are done adding actions to this Events tag, click Save.
Was this article helpful?