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 List Environments operation, it retrieves a list of all environments associated with a specified GTM container.

Common scenarios where this node is beneficial include:

  • Automating the retrieval of environment configurations for auditing or reporting.
  • Integrating GTM environment data into broader marketing or analytics workflows.
  • Synchronizing environment information across multiple systems or teams.

For example, a user might use this node to fetch all environments in a container to verify deployment stages (e.g., development, staging, production) before triggering further automation steps.

Properties

Name Meaning
Account ID The unique identifier of the GTM Account containing the container.
Container ID The unique identifier of the GTM Container whose environments are to be listed.
Optional Query Parameters Additional optional parameters to refine or control the API request.

The Optional Query Parameters collection can include various flags and filters, but for the "List Environments" operation, typically no additional parameters are required.

Output

The output is a JSON array where each item represents an environment object retrieved from the GTM API. Each environment object contains details such as environment name, URL, authorization codes, and other metadata defined by GTM.

The structure corresponds directly to the Google Tag Manager Environment resource representation, including fields like:

  • name: The environment's display name.
  • url: The URL associated with the environment.
  • Other environment-specific properties as returned by the GTM API.

No binary data is output by this operation.

Dependencies

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

Troubleshooting

  • Missing Credentials Error: If the node throws an error about missing credentials, ensure that the Google Tag Manager OAuth2 API credentials are properly set up in n8n.
  • Required Parameter Errors: The node requires both Account ID and Container ID to be provided. Omitting either will result in an error indicating the missing parameter.
  • API Request Failures: Errors returned from the GTM API (e.g., permission denied, invalid IDs) will be surfaced with messages prefixed by "Error calling GTM API". Verify that the account and container IDs are correct and that the authenticated user has access.
  • Pagination: If there are many environments, the API may paginate results. Use the optional query parameter pageToken to handle pagination if needed.

Links and References


This summary focuses on the "Environment" resource and the "List Environments" operation as requested, based on static analysis of the provided source code and property definitions.

Discussion