# n8n-nodes-google-tag-manager

[![npm version](https://img.shields.io/npm/v/@measurementmatter/n8n-nodes-google-tag-manager.svg)](https://www.npmjs.com/package/@measurementmatter/n8n-nodes-google-tag-manager)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)

A community node for [n8n](https://n8n.io/) that enables full interaction with the [Google Tag Manager API v2](https://developers.google.com/tag-platform/tag-manager/api/v2) directly from your automation workflows.

Developed and maintained by [Measurement Matter](https://github.com/measurementmatter).

[n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/reference/license/) workflow automation platform.

---

## Table of Contents

- [Installation](#installation)
- [Credentials](#credentials)
- [Supported Resources & Operations](#supported-resources--operations)
- [Using as a Tool](#using-as-a-tool)
- [Compatibility](#compatibility)
- [Resources](#resources)

---

## Installation

Install via the n8n interface by following the [community nodes installation guide](https://docs.n8n.io/integrations/community-nodes/installation/).

Or manually:

```sh
git clone https://github.com/measurementmatter/n8n-nodes-google-tag-manager.git
cd n8n-nodes-google-tag-manager
npm install
```

Then place the node in your `~/.n8n/custom-nodes` directory (or follow instructions specific to your n8n installation).

---

## Credentials

This node uses **OAuth 2.0** authentication via Google Cloud.

### Steps to obtain API credentials

1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or use an existing one
3. Enable the **Google Tag Manager API**
4. Create API credentials (OAuth 2.0)
5. Add them to the authentication settings in n8n

---

## Supported Resources & Operations

| Resource | Operations |
|----------|------------|
| **Account** | Get, List, Update |
| **Built-In Variable** | Create, Delete, List, Revert |
| **Client** | Create, Delete, Get, List, Revert, Update |
| **Container** | Combine, Create, Delete, Get, List, Lookup, Move tag ID, Get tagging snippet, Update |
| **Destination** | Add, Get, List |
| **Environment** | Create, Delete, Get, List, Regenerate authorization code, Update |
| **Folder** | Create, Delete, List entities, Get, List, Move entities, Revert, Update |
| **Google Tag Configuration** | Create, Delete, Get, List, Update |
| **Tag** | Create, Delete, Get, List, Revert, Update |
| **Template** | Create, Delete, Get, Import from gallery, List, Revert, Update |
| **Transformation** | Create, Delete, Get, List, Revert, Update |
| **Trigger** | Create, Delete, Get, List, Revert, Update |
| **User Permission** | Create, Delete, Get, List, Update |
| **Variable** | Create, Delete, Get, List, Revert, Update |
| **Version Header** | Get latest, List |
| **Version** | Delete, Get, Get live, Publish, Set latest, Undelete, Update |
| **Workspace** | Create, Create container version, Delete, Find conflicts, Get, List, Quick preview, Resolve merge conflict, Sync, Update |
| **Zone** | Create, Delete, Get, List, Revert, Update |

Retrieve information from the [GTM API](https://developers.google.com/tag-platform/tag-manager/api/v2).

---

## Using as a Tool

This node can be used as a tool in n8n AI Agents. To enable community nodes as tools, you need to set the `N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE` environment variable to `true`.

| Environment | How to set |
|-------------|------------|
| **bash/zsh** | `export N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true` then `n8n start` |
| **Docker** | Add `- N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true` under `environment:` in your `docker-compose.yml` |
| **Desktop app** | Create a `.env` file in the n8n directory with `N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true` |
| **Permanent (Mac/Linux)** | Add `export N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true` to your `~/.zshrc` or `~/.bash_profile` |

---

## Compatibility

Tested with n8n **v1.80.5** (Success)

---

## Resources

- [n8n community nodes documentation](https://docs.n8n.io/integrations/community-nodes/)
- [Google Tag Manager API documentation](https://developers.google.com/tag-platform/tag-manager/api/v2)

---

## License

Distributed under the [MIT License](LICENSE.md).
