Skip to content

Clarify to remove GTM snippet #2720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/connections/destinations/catalog/google-tag-manager/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ id: 54521fd625e721e32a72eeb9

## Getting Started

{% include content/connection-modes.md %}

1. From the Segment web app, click **Catalog**.
2. Search for "Google Tag Manager" in the Catalog, select it, and choose which of your sources to connect the destination to.
3. In your Segment UI's destination settings, enter your Container ID (note: it should start with "GTM-"). You can find this in the Admin section of your [GTM dashboard](https://tagmanager.google.com/#/admin/).
4. GTM will be loaded on any pages where your Segment snippet is initialized and `analytics.page` gets called in client-side Javascript. Once you've turned on GTM through Segment, you can use Segment `track` events to populate the GTM `dataLayer`.
4. GTM loads on any pages where your Segment snippet is initialized and `analytics.page` is called in client-side Javascript. Once you've turned on GTM through Segment, you can use Segment `track` events to populate the GTM `dataLayer`, and remove the GTML snippet from your page.

**Notes**
* We recommend loading GTM through Segment rather than loading Segment inside of GTM.
* Segment recommends that you load GTM through Segment rather than loading Segment inside of GTM.
* Be sure to "publish" your GTM container in GTM before trying to load it through Segment, otherwise your container URL will return a 404 error.


## Page
If you're not familiar with the Segment Specs, take a look to understand what the [Page method](/docs/connections/spec/page/) does. An example call would look like:

```js
analytics.page('Home', {
analytics.page('Home', {
title: 'Welcome | My Website',
url: 'https://mywebsite.com/'
});
```

You must call the Page method for Google Tag Manager to load. We already include a call to `analytics.page` 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.
You must call the Page method for Google Tag Manager to load. Segment includes a call to `analytics.page` 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.

### Tracking All Pages
When you turn on the setting to **Track All Pages** in your Optional Settings, we will track events whenever you call our `page` method and send a "Loaded A Page" event to Google Tag Manager. See the `track` section below for more info on how we send events to GTM.
When you turn on the setting to **Track All Pages** in your Optional Settings, Segment tracks events whenever you call the `page` method and send a "Loaded A Page" event to Google Tag Manager. See the `track` section below for more info on how Segment sends events to GTM.

### Named Page Events
If you include a `name` parameter in your `page` calls and turn on the setting to **Track Named Pages** in your Optional Settings, we will also pass on an event to GTM for that page. For example, `analytics.page('Signup')` would translate to a "Viewed Signup Page" event. See the `track` section below for more info on how we send events to GTM.
If you include a `name` parameter in your `page` calls and turn on the setting to **Track Named Pages** in your Optional Settings, Segment passes on an event to GTM for that page. For example, `analytics.page('Sign up')` would translate to a "Viewed Sign up Page" event. See the `track` section below for more info about how Segment sends events to GTM.

### Categorized Page Events
If you include a `category` parameter in your `page` calls and turn on the setting to **Track Categorized Pages** in your Optional Settings, we will also pass on an event to GTM for that page. For example, `analytics.page('Docs', 'Index')` would translate to a "Viewed Docs Index Page" event. See the `track` section below for more info on how we send events to GTM.
If you include a `category` parameter in your `page` calls and turn on the setting to **Track Categorized Pages** in your Optional Settings, Segment passes an event to GTM for that page. For example, `analytics.page('Docs', 'Index')` would translate to a "Viewed Docs Index Page" event. See the `track` section below for more info about how Segment sends events to GTM.


## Track
Expand All @@ -54,7 +53,7 @@ analytics.track('Article Completed', {
});
```

When you make a Track call in with GTM enabled through Segment, we will push the event data to the GTM `dataLayer`.
When you make a Track call in with GTM enabled through Segment, the event data is pushed to the GTM `dataLayer`.

For example, if you make this `track` call:

Expand All @@ -65,7 +64,7 @@ analytics.track('Played Video', {
})
```

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

```json
{
Expand All @@ -86,7 +85,7 @@ If you are seeing `404` error on the javascript console of your page and it is a
## Appendices

### 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`.
By default Segment pushes the `anonymousId` and `userId`(if exists) into the `dataLayer` for each `page` or `track` call. Since the `anonymousId` is created by Segment, namespaces that property in the `dataLayer` as `segmentAnonymousId`.

### Environments
If you're using an 'environment' variable for `gtm_preview` in your tag's query string, you can set that string in the **Environment** of your Optional Settings. IMPORTANT: Make sure the string includes the `gtm_auth` variable. For example, your string should look like: `env-xxxxx&gtm_auth=xxxxx`.