Google Tag Manager Device Mode Integration

Send events to Google Tag Manager using RudderStack device mode.

After you have successfully instrumented Google Tag Manager as a destination in RudderStack, follow this guide to correctly send your events to Google Tag Manager in device mode.

Identify

You can use the identify call to identify a user, record their traits like name, email address, etc., and send this information to Google Tag Manager.

A sample identify call is shown:

rudderanalytics.identify("1hKOmRA4GRlm",{
"name":"Alex Keener",
"gender":"Male",
"city":"New Orleans"
})

The above call populates Google Tag Manager with the following user traits along with their values:

  • userId
  • name
  • gender
  • city

Page

The page call allows you to record whenever a user visits a page of your website, along with the properties associated with that page.

warning
You must call the page event to load Google Tag Manager .

A sample page call is shown below:

rudderanalytics.page("home", {
  path: "path",
  url: "url",
  title: "title",
  search: "search",
  referrer: "referrer"
});

The above call populates Google Tag Manager with the following properties along with their values:

  • userId
  • anonymousId
  • event - the viewed home page
  • path
  • url
  • title
  • search
  • referrer
info
Making a page call sends out an object to the GTM data layer containing your page-related properties and an event name with its associated value.

Track

The track call lets you record any user actions along with the properties associated with those actions.

info
You can use the RudderStack track events to populate the Google Tag Manager data layer once you have set up and enabled Google Tag Manager in RudderStack.

Calling the RudderStack SDK track method with the event and its properties similarly passes the data to GTM as seen in the page section above.

rudderanalytics.track("Track me", {
  category: "category",
  label: "label",
  value: "value",
});

The above call populates Google Tag Manager with the following properties along with their values:

  • userId
  • anonymousId
  • event
  • category
  • label
  • value


Questions? Contact us by email or on Slack