google-tag-manager-controller

Google Tag Manager Python API

🐍 Table of Contents 🐍

⚡ About ⚡

The Google Tag Manager API provides access to Google Tag Manager configuration data for an authorized user. With this API you can manage: accounts, containers, worksapces, tags, triggers and variables

Benefit

The Google Tag Manager API handles millions of operations. To protect the system from receiving more operations than it can handle, and to ensure an equitable distribution of system resources, it is necessary to employ a quota system.

Info

https://developers.google.com/tag-manager/api/v2/reference
https://developers.google.com/tag-manager/api/v2/devguide

Software architecture

GitHub Logo

Quota Limits

  • 50,000 requests per project per day, which can be increased.
  • 10 queries per second (QPS) per IP address
  • By default, it is set to 100 requests per 100 seconds per user
  • This can be adjusted to a maximum value of 1,000.

Setup

0. activate venv

python -m venv venv
source ./venv/bin/activate (Mac) or venv\Scripts\activate (Windows)

1. install the packages

pip install -r requirements.txt

2. create the service account & OAuth client in GCP for the Google Tag Manager API

https://console.cloud.google.com/

3. download the client secrets.json (OAuth 2.0 Client ID)

4. create conf repository and locate client_secrets.json into this repository

mkdir conf
mv xxxxx-xxxxx.json client_secrets.json

5. create .env and put there private key and sensitive information

touch .env

6. setup the .env

  • CLIENT_SECRETS=’conf/client_secrets.json’
  • ACCOUNT_ID=’xxxx’
  • CONTAINER_NAME=’xxxx’
  • CONTAINER_ID=’xxxx’
  • WORKSPACE_NAME=’xxxx’
  • WORKSPACE_ID=’xx’

7. setup GTM account info

CLIENT_SECRETS = config('CLIENT_SECRETS')
ACCOUNT_ID = config('ACCOUNT_ID')
CONTAINER_NAME= config('CONTAINER_NAME')
CONTAINER_ID = config('CONTAINER_ID')
WORKSPACE_NAME = config('WORKSPACE_NAME')
WORKSPACE_ID = config('WORKSPACE_ID')

8. RUN GTM Scanner to see the GTM information

you can scan the account, container, workspace, tag, trigger, variable information by using gtm_scanner.py

python project/run_scanner.py

8. RUN GTM Creator

you can create new workspaces, tags, triggers, variables and publish these by using gtm_creator.py

python project/run_creator.py

Visit original content creator repository

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *