Skip to content

This project is using both Google Tag Manager API and Google Analytics API. Create javascript snippet code for your Google Tag Manager by providing your Site Name, Site URL. This service will connect to your Google Analytics account to create a new web property for your account based on Site Name and Site URL command line params. After creating …

Notifications You must be signed in to change notification settings

lalatgithub/python-google-tag-manager-analytics

Repository files navigation

Google Tag Manager Python API integrated with Analytics API

This project is using both Google Tag Manager API and Google Analytics API. Create javascript snippet code for your Google Tag Manager by providing your Site Name, Site URL. This service will connect to your Google Analytics account to create a new web property for your account based on Site Name and Site URL command line params. After creating web property, it will get web property's tracking code to feed it into Google Tag Manager. This project creates Universal Analytics Tag

Warning from Google Analytics API docs
Write operations in the Management API (e.g. create, update, delete, patch) for Web Property,
View (Profile), and Goal resources are currently available as a developer preview in limited beta.
If you're interested in using these features, request access to the beta.

Please create a project on Google Developer Console and apply to request access to beta before creating a web property to get tracking code.


Enable required APIs

Enable Google Tag Manager API

Enable Google Analytics API


Make required changes in settings.py
 #enable/disable sending javascript code snippet in email.
SEND_CODE_SNIPPET_EMAIL = True

# SMPT settings goes here...

# secret key must be in /secrets/ folder. otherwise change directory here
# How to get secret key JSON file. Follow link
# https://developers.google.com/tag-manager/api/v1/devguide#environment

GOOGLE_DEVELOPER_SECRET_KEY = os.path.join('secrets', 'google_developer_secret.json')

TIME_ZONE_COUNTRY_ID = 'US'
TIME_ZONE_ID = 'America/Los_Angeles'

# possible values: web, android, ios
GOOGLE_TAG_USAGE_CONTEXT = ['web']

Switch to project root directory and Install dependencies from requirements.txt file
pip install -r requirements.txt

What command do i need to execute?
# simply run from the command line
python index.py --site_name MY_SITE_NAME --site_url MY_SITE_URL

What do you get?

Google Tag Manager Preview


Tested Environment
Python 2.7
Python 3.4
Google Tag Manager API Version 1
Google Analytics API Version 3
Ubuntu 14.04

About

This project is using both Google Tag Manager API and Google Analytics API. Create javascript snippet code for your Google Tag Manager by providing your Site Name, Site URL. This service will connect to your Google Analytics account to create a new web property for your account based on Site Name and Site URL command line params. After creating …

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages