Google Tag Manager Destination

Segment makes it easy to send your data to Google Tag Manager (and lots of other destinations). Once you've tracked your data through our open source libraries we'll translate and route your data to Google Tag Manager in the format they understand. Learn more about how to use Google Tag Manager with Segment.

Getting Started

GTM will be loaded on any pages where your Segment snippet is initialized and gets called in client-side javascript. We recommend loading GTM through Segment rather than loading Segment inside of GTM.

Once you’ve turned on GTM through Segment you can use GTM to trigger Segment events by entering analytics.track or calls into GTM. Be sure to “publish” your GTM container in GTM before trying to load it through Segment, otherwise your container url will 404.


You must call page for Google Tag Manager to load. We already include a call to in your default Segment snippet, so if you haven’t removed that, GTM will work the same as if you installed the GTM snippet directly.

Named Page Events

If you include a name parameter in your page calls, and turn on the setting to Track Named Pages in your Advanced Options tab under GTM in Segment we will also pass on an event to GTM for that page. See the track section below for more info on how we send events to GTM.


When you make a track call in client-side javascript with Google Tag Manager enabled through Segment we will push the event data to the GTM dataLayer.

For example, if you make this track call:

analytics.track('Played Video', {
  title: 'How to Dance the Tango',
  location: 'Tango FAQ Page'

We will pass it to the dataLayer as an object like this:

  event: 'Played Video',
  title: 'How to Dance the Tango',
  location: 'Tango FAQ Page'

UserId and AnonymousId

By default we will also push the anonymousId and userId(if exists) into the dataLayer for each page or track call. Since the anonymousId is created by Segment, we will namespace that property in the dataLayer as segmentAnonymousId.



If you are seeing 404 on the javascript console of your page and it is attributed to Google Tag Manager, it is likely that you have yet to publish your GTM container.

Supported Sources and Connection Modes

📱 Device-based
☁️ Cloud-based

To learn more about about Connection Modes and what dictates which we support, see here.


Segment lets you change these destination settings via your Segment dashboard without having to touch any code.

Container ID

You can find your Container ID in your Accounts page.


If you’re using an ‘environment’ variable for gtm_preview in your tag’s query string, you can put that string here. IMPORTANT: make sure the string includes gtm_auth. For example, your string should look like env-xx&gtm_auth=xxxxxx

Track All Pages

This will track events titled ‘Loaded A Page’ to Google Tag Manager whenever you call our page method

Track Categorized Pages

This will track events to Google Tag Manager for page method calls that have a category associated with them. For example page('Docs', 'Index') would translate to Viewed Docs Index Page.

Track Named Pages

This will track events to Google Tag Manager for page method calls that have a name associated with them. For example page('Signup') would translate to Viewed Signup Page.

If you have any questions or see anywhere we can improve our documentation, please let us know or kick off a conversation in the Segment Community!