Google Tag Manager icon

Google Tag Manager

Use the Google Tag Manager API

Actions102

Overview

This node integrates with the Google Tag Manager (GTM) API, allowing users to manage various GTM resources programmatically within n8n workflows. Specifically, for the Environment resource and the Create Environment operation, it enables creating a new environment inside a specified GTM container.

Common scenarios where this node is beneficial include automating GTM environment setup during deployment pipelines, managing multiple environments (e.g., development, staging, production), or integrating GTM environment creation into broader marketing or analytics automation workflows.

For example, when launching a new website version, you might automatically create a corresponding GTM environment to test tags before publishing them live.

Properties

Name Meaning
Account ID The unique identifier of the GTM Account under which the environment will be created.
Container ID The unique identifier of the GTM Container where the environment will be created.
Optional Query Parameters Additional optional parameters that can modify the request behavior. Includes:
- Allow User Permission Feature Update (boolean): Allows user permission feature updates.
- Built-In Variable Type (options): Various built-in variable types (not directly relevant here).
- Copy Settings (boolean): Whether to copy tag settings from another tag (if applicable).
- Copy Terms Of Service (boolean): Accept terms of service agreements copied from current tag.
- Copy Users (boolean): Whether to copy users from another tag.
- Destination ID, Fingerprint, Include Google Tags, Page Token, Setting Source, Tag ID, etc.:
Various other optional parameters mostly related to other operations/resources.
Request Body JSON object containing the details of the environment to create, such as its name, URL, and description.

Note: For the Create Environment operation, the critical inputs are Account ID, Container ID, and the Request Body describing the environment properties.

Output

The node outputs an array of JSON objects representing the response from the Google Tag Manager API after creating the environment. This typically includes the full details of the newly created environment, such as:

  • Environment ID
  • Name
  • URL
  • Description
  • Authorization code (if applicable)
  • Other metadata returned by the GTM API

No binary data output is involved in this operation.

Dependencies

  • Requires valid Google Tag Manager API credentials configured in n8n using OAuth2 authentication.
  • The node uses the official GTM API endpoint at https://www.googleapis.com/tagmanager/v2.
  • Proper permissions on the GTM account and container are necessary to create environments.

Troubleshooting

  • Missing Credentials Error: If the node throws an error about missing credentials, ensure that the Google Tag Manager API OAuth2 credentials are properly set up in n8n.
  • Required Parameter Errors: The node validates required parameters like Account ID and Container ID. Missing these will cause errors. Double-check that these IDs are correctly provided.
  • API Errors: Errors returned from the GTM API (e.g., permission denied, invalid request body) will be surfaced with messages prefixed by "Error calling GTM API". Review the message and stack trace for details.
  • Invalid Request Body: Ensure the JSON in the Request Body is well-formed and matches the expected schema for a GTM environment.

Links and References

Discussion