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. Specifically, the "Update Template" operation under the "Template" resource enables updating an existing custom template within a GTM container workspace.

Common scenarios for this node include automating GTM workspace management tasks such as updating templates, tags, triggers, variables, and other GTM entities without manual intervention in the GTM web interface. For example, marketing teams can automate updates to tracking templates or developers can integrate GTM changes into CI/CD pipelines.

Practical example: You have a custom tag template in GTM that needs periodic updates based on new tracking requirements. Using this node's "Update Template" operation, you can push updated template JSON definitions directly from your workflow, ensuring consistent deployment across environments.

Properties

Name Meaning
Account ID The GTM Account ID where the template resides.
Container ID The GTM Container ID containing the workspace and template.
Workspace ID The GTM Workspace ID within the container where the template exists.
Template ID The specific GTM Template ID to update.
Optional Query Parameters Additional optional parameters for the API call, such as allowUserPermissionFeatureUpdate (boolean), fingerprint (string), etc. These control advanced behaviors of the update request.
Request Body The JSON object representing the updated template data to send in the update request body.

Output

The node outputs an array of JSON objects corresponding to the responses from the GTM API calls. For the "Update Template" operation, the output JSON contains the updated template resource as returned by the GTM API, including all its properties after the update.

No binary data is output by this node.

Dependencies

  • Requires valid Google Tag Manager API credentials configured in n8n (an OAuth2 API credential).
  • The node makes HTTP requests to the GTM API endpoint at https://www.googleapis.com/tagmanager/v2.
  • Proper permissions on the GTM account and container are necessary to perform update operations.

Troubleshooting

  • Missing Credentials: If the node throws an error about missing credentials, ensure that a valid Google Tag Manager OAuth2 credential is configured and selected.
  • Required Parameter Errors: The node validates required IDs (Account ID, Container ID, Workspace ID, Template ID). Missing any of these will cause errors. Double-check that all required fields are provided.
  • API Errors: Errors returned from the GTM API (e.g., permission denied, invalid template JSON) will be surfaced with messages prefixed by "Error calling GTM API". Review the message and stack trace for details.
  • Fingerprint Mismatch: If using the optional fingerprint parameter, ensure it matches the current fingerprint of the template resource; otherwise, the update will fail.
  • Invalid JSON in Request Body: Ensure the JSON provided in the Request Body property is well-formed and matches the expected schema for a GTM template.

Links and References

Discussion