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, for the Folder resource and the Delete Folder operation, it enables deleting a folder within a specified GTM workspace. This is useful in scenarios where you want to automate the cleanup or restructuring of your GTM container workspaces by removing obsolete or unnecessary folders.

Practical examples include:

  • Automatically deleting folders that are no longer needed after a deployment.
  • Cleaning up test or temporary folders created during development.
  • Managing GTM workspace organization as part of a larger automation workflow.

Properties

Name Meaning
Account ID The unique identifier of the GTM Account containing the folder.
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 folder exists.
Folder ID The unique identifier of the GTM Folder to be deleted.
Optional Query Parameters Additional optional parameters for the API call; can include flags like allowUserPermissionFeatureUpdate and others (not typically required for delete).

Output

The output is a JSON array containing the response from the Google Tag Manager API after attempting to delete the specified folder. Typically, for a delete operation, the API returns an empty object {} or confirmation of deletion. The node outputs this raw JSON response, which can be used downstream in workflows to confirm success or handle errors.

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 Google Tag Manager v2 REST API endpoint: https://www.googleapis.com/tagmanager/v2.
  • Proper permissions on the GTM account and workspace are necessary to perform folder deletions.

Troubleshooting

  • Missing Required IDs: If any of the required IDs (Account ID, Container ID, Workspace ID, Folder ID) are missing, the node will throw an error indicating which ID is required.
  • Authentication Errors: Ensure that the Google Tag Manager API credentials are correctly set up and authorized.
  • Permission Denied: The authenticated user must have sufficient permissions to delete folders in the specified workspace.
  • Folder Not Found: If the Folder ID does not exist or is incorrect, the API will return an error.
  • API Rate Limits: Excessive requests may lead to rate limiting by Google APIs; implement retries or backoff strategies if needed.

Common error message example:

Error calling GTM API: [detailed error message]

Resolution steps:

  • Verify all input IDs are correct.
  • Check API credentials and permissions.
  • Review the full error stack trace for more details.

Links and References

Discussion