Google Tag Manager Destination Config Reference
- free
- growth
- enterprise
6 minute read
Google Tag Manager is a web device mode tag management destination. RudderStack’s JavaScript SDK loads your Tag Manager container in the browser and pushes track, page, and identify calls to the container’s data layer, where your tags and triggers act on them.
In a Google Tag Manager destination spec:
type: gtmdefinition_version: 1
Sample configuration
version: rudder/v1
kind: destination
metadata:
name: gtm-staging
spec:
id: gtm-staging
display_name: Google Tag Manager Staging
type: gtm
definition_version: 1
enabled: true
config:
container_id: "{{ .GTM_CONTAINER_ID }}"
server_url: https://tags.example.com
environment_id: env-5
authorization_token: "{{ .GTM_AUTHORIZATION_TOKEN }}"
event_filtering:
blacklist:
- Credit Card Added
connection_mode:
web: device
consent_management:
web:
- provider: oneTrust
consents:
- analyticsThe above example loads the container’s staging environment from a custom domain — see Environments — and keeps Credit Card Added events out of the data layer.
Config keys
config accepts only the keys listed below. The shared config key rules cover unknown keys, defaults, and immutability.
Google Tag Manager runs only in web device mode. Every key on this page configures how the SDK loads the container, or which events it pushes to the data layer:
track— pushed under its event name, withuserId,anonymousId,traits,messageId, and the event’s properties.page— pushed asViewed <category> <name> page,Viewed <name> pagewhen the call has no category, orViewed a Pagewhen it has no name, with the same fields.identify— pushed as atraitsobject, with no event name.
Container
container_id
RequiredSecretType:
string
Description:
ID of the Tag Manager container to load, in the form GTM-XXXXXXX, from the Admin section of Tag Manager.
Notes:
- At most 100 characters, and must not contain line breaks.
- A
{{ path || fallback }}template is accepted in place of a literal.
Supply it as a {{ .VAR }} reference rather than a literal — see Secrets.
server_url
Type:
string
Description:
Domain that serves the container’s gtm.js instead of https://www.googletagmanager.com — for example, a server-side Tag Manager container on your own domain. The SDK loads <server_url>/gtm.js?id=<container_id>. The dashboard calls it Custom Domain URL.
Notes:
- Must be a domain URL. Any value containing
.ngrok.iois rejected. - A
{{ path || fallback }}template is accepted in place of a literal. - Write the scheme, and leave off the trailing slash. Rudder CLI accepts a value without
https://, but the SDK uses the value as is, sotags.example.comalone loads the script relative to the current page.
server_url: https://tags.example.comEnvironments
environment_id and authorization_token load a Tag Manager environment, such as staging, instead of the container’s live version. Both come from the environment’s snippet in Tag Manager — Environments > Actions > Get Snippet — as its gtm_preview and gtm_auth values. Leave both unset to load the live version.
environment_id
Type:
string
Description:
ID of the environment to load — the gtm_preview value, such as env-5.
Notes:
- At most 100 characters, and must not contain line breaks.
- Templates aren’t accepted in place of a literal; a template is measured as text against the same limit.
- Set it together with
authorization_token. Rudder CLI accepts either one without the other.
authorization_token
SecretType:
string
Description:
Authorization token of that environment — the gtm_auth value.
Notes:
- At most 100 characters, and must not contain line breaks.
- Templates aren’t accepted in place of a literal; a template is measured as text against the same limit.
{{ .VAR }} reference rather than a literal — see Secrets.Event filtering
event_filtering
Type:
object
Description:
Restricts which track events the SDK pushes to the data layer, by event name. page and identify calls aren’t filtered. See Client-side Events Filtering.
Notes:
whitelist— array of event names to allow; every othertrackevent is dropped.blacklist— array of event names to drop; every othertrackevent is allowed.- The two are mutually exclusive, and Rudder CLI enforces it — setting both fails validation.
- Each name is at most 100 characters, or a
{{ path || fallback }}template. - Omit the block entirely to filter nothing.
event_filtering:
whitelist:
- Order Completed
- Product AddedPer-source keys
Both keys are objects keyed by the local source type — the tokens listed under Source types. A key naming a source type this destination doesn’t support fails validation.
connection_mode
Type:
object
Description:
Maps each source type you connect to the mode its events reach Google Tag Manager in. Google Tag Manager accepts only web: device.
Notes:
- An entry is required for each source type you connect — see Connect a source.
connection_mode:
web: deviceconsent_management
Type:
object
Description:
Consent provider configuration per source type. The entry shape, accepted providers, and the rules on resolution_strategy and consents are shared across all destination types — see Consent management.
Source types
Google Tag Manager accepts events from these source types in the mentioned connection modes:
| Source type | Connection mode |
|---|---|
web | device |
Google Tag Manager accepts only web sources, and only in device mode — the SDK loads the container in the browser, and no events pass through RudderStack’s servers. See Google Tag Manager device mode.
Connect a source
An event stream connection to this destination is checked against two rules at validate time.
The source’s type must be supported. Google Tag Manager accepts only web, the type a JavaScript source resolves to. Every other source resolves to a type it doesn’t accept — an iOS source to ios, an Android source to android, and webhook and server-side SDK sources to cloud — and reports, for example:
destination 'gtm-staging' (type 'gtm') does not support source 'my-ios-app':
source type 'ios' is not among supported source types: webThe destination config must carry a connection_mode entry for that source type. This lives on the destination spec, not on the connection spec. Without it:
destination 'gtm-staging' config has no 'connection_mode' entry for source type 'web'Google Tag Manager needs no additional config keys to connect a web source.
Secrets
container_id and authorization_token are the secret keys. Write each one you use as a {{ .VAR }} reference and supply the value at apply time:
config:
container_id: "{{ .GTM_CONTAINER_ID }}"
authorization_token: "{{ .GTM_AUTHORIZATION_TOKEN }}"export RUDDER_GTM_CONTAINER_ID="..."
export RUDDER_GTM_AUTHORIZATION_TOKEN="..."
rudder-cli apply
# or
rudder-cli apply --var-file secrets.vars.yamlNote that:
rudder-cli importwrites only the secrets the API returns, as{{ .VAR }}references, and leaves the others out. Add any secret key it leaves out, then supply the variables before you apply — see Secrets.- The browser requests
gtm.jswith these values in its URL, so masking them protects your YAML, not the values themselves.
See How to Use Variable Substitution in Rudder CLI.
Changes by release
No changes since this type became available.
For changes across every destination type, see Destination Type Changes by Release.
See more
- Google Tag Manager Destination for the container ID, environments, and loading RudderStack as a custom HTML tag
- Google Tag Manager Device Mode for how
identify,page, andtrackcalls reach the data layer - Destination Type Reference for Rudder CLI for the rules shared across destination types
- Destination YAML Reference for the spec envelope