> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/g/google-tag-manager.md).

# Google Tag Manager

Google Tag Manager manages marketing and analytics tags. OctoXLabs reads the users that have access to your Tag Manager accounts and containers.

## Use cases

* Review who can change tags and containers in your Tag Manager accounts.
* Check what one Tag Manager connection collected.

```
Connections = YOUR_CONNECTION_NAME
```

## Before you begin

### Network

| Source              | Destination                                      | Port         | Protocol     |
| ------------------- | ------------------------------------------------ | ------------ | ------------ |
| OctoXLabs connector | Google Tag Manager API and Google OAuth endpoint | Not verified | Not verified |

### Required permissions

| Scope or role                                                            | Permission     | Needed for                       |
| ------------------------------------------------------------------------ | -------------- | -------------------------------- |
| Tag Manager API enabled in the Google Cloud project                      | Enabled        | API access                       |
| Administrator account permission in every Tag Manager account to collect | Administrator  | Listing the users of an account  |
| `tagmanager.manage.users` OAuth scope                                    | Used read only | Required by Google to list users |

The adapter only reads data. Users without any account or container access are not collected.

## Create credentials in Google Tag Manager

{% stepper %}
{% step %}

### Create a service account

Open the [Service accounts page](https://console.cloud.google.com/iam-admin/serviceaccounts) of a Google Cloud project and create a service account.
{% endstep %}

{% step %}

### Enable the Tag Manager API

In the same project, go to **APIs & Services** > **Library** and enable the **Tag Manager API**.
{% endstep %}

{% step %}

### Create a JSON key

Open the service account, go to the **Keys** tab, select **Add key** > **Create new key**, choose **JSON** and upload the file in OctoXLabs.
{% endstep %}

{% step %}

### Add the service account in Tag Manager

In Google Tag Manager, open **Admin** > **User Management** of every account to collect, add the service account email and give it the **Administrator** account permission.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
The key file is the only copy of the private key. Store it securely and create a new key if it is lost.
{% endhint %}

{% hint style="info" %}
The Tag Manager API allows about 25 requests per 100 seconds per Google Cloud project, so the adapter waits between requests and discovery takes a few seconds per account.
{% endhint %}

## Connection parameters

| Parameter                | Required | Type    | Default | Description                                                                                                                                                |
| ------------------------ | -------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Service Account Email    | Yes      | String  | None    | Email of the Google Cloud service account. It must match the `client_email` of the key file.                                                               |
| Service Account Key File | Yes      | File    | None    | JSON key file of the service account.                                                                                                                      |
| Workspace Admin Email    | No       | String  | None    | Google Workspace user to impersonate through domain-wide delegation. Leave it empty when the service account itself was added to the Tag Manager accounts. |
| Https Proxy              | No       | String  | None    | Proxy URL.                                                                                                                                                 |
| Timeout                  | No       | Integer | 30      | Time in seconds to wait for API responses.                                                                                                                 |

Required flags and types come from the frontend instructions and were not checked against connector code.

## Troubleshooting

| Error message | Cause                                               | Fix                                                     |
| ------------- | --------------------------------------------------- | ------------------------------------------------------- |
| Not verified  | Error texts could not be taken from connector code. | Run the connection test and check the parameters above. |

## Change history

{% hint style="info" %}
Available starting from version 6.9.1.
{% endhint %}
