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, specifically enabling management of GTM Triggers among many other resources. The "Create Trigger" operation allows users to create a new trigger within a specified GTM workspace, container, and account. This is useful for automating the setup of triggers that control when tags fire in GTM, such as page views, clicks, or custom events.

Practical scenarios include:

  • Automatically creating triggers during deployment pipelines.
  • Managing GTM configurations programmatically without manual UI interaction.
  • Integrating GTM trigger creation into broader automation workflows.

Properties

Name Meaning
Account ID The unique identifier of the GTM Account where the trigger will be created.
Container ID The unique identifier of the GTM Container within the account.
Workspace ID The unique identifier of the GTM Workspace inside the container where the trigger will be added.
Optional Query Parameters Additional optional parameters for the API request; includes various flags and settings.
Request Body JSON object representing the details of the trigger to create, including its configuration.

Details on Optional Query Parameters (subset relevant to triggers):

  • Various boolean flags and options related to user permissions, copying settings, and specifying types are available but typically not required for basic trigger creation.

Output

The node outputs an array of JSON objects representing the response from the Google Tag Manager API after creating the trigger. The output JSON structure corresponds directly to the GTM API's trigger resource representation, which typically includes fields such as:

  • triggerId: The unique identifier of the created trigger.
  • name: The name of the trigger.
  • type: The type of trigger (e.g., click, page view).
  • Other configuration details defining the trigger behavior.

No binary data output is involved.

Dependencies

  • Requires valid Google Tag Manager API credentials configured in n8n (an OAuth2 API credential).
  • Internet access to call the Google Tag Manager API endpoint at https://www.googleapis.com/tagmanager/v2.
  • Proper permissions on the GTM account to create triggers.

Troubleshooting

  • Missing Credentials: If the Google Tag Manager API credentials are not set up or invalid, the node will throw an error indicating missing credentials.
  • Required Parameter Missing: Errors will occur if any of the required IDs (accountId, containerId, workspaceId) are not provided.
  • Invalid Request Body: If the JSON body describing the trigger is malformed or missing required fields, the API may reject the request.
  • API Errors: Any errors returned by the GTM API (such as permission denied, quota exceeded, or invalid parameters) will be surfaced with descriptive messages.
  • To resolve errors, ensure all required parameters are correctly set, the request body is valid JSON matching GTM trigger schema, and credentials have sufficient permissions.

Links and References

Discussion