{ "info": { "author": "Trakken Web Services", "author_email": "christian@trakken.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# GTM Manager (WIP)\n\n![Build Status](https://img.shields.io/pypi/pyversions/gtm-manager.svg)\n[![Build Status](https://travis-ci.org/trakken/gtm_manager.svg?branch=master)](https://travis-ci.org/trakken/gtm_manager)\n[![Documentation Status](https://img.shields.io/pypi/v/gtm-manager.svg)](https://pypi.org/project/gtm-manager/)\n[![Documentation Status](https://readthedocs.org/projects/gtm-manager/badge/?version=latest)](https://gtm-manager.readthedocs.io/en/latest/?badge=latest)\n\nAn object-oriented helper library wrapping the [Tag Manager API Client Library for Python](https://developers.google.com/api-client-library/python/apis/tagmanager/v2) for the [Google Tag Manager API](https://developers.google.com/tag-manager/api/v2/).\n\n```bash\npip3 install gtm_manager\n```\n\nDocumentation: [https://gtm-manager.readthedocs.io](https://gtm-manager.readthedocs.io/en/latest)\n\n## Installation from Source\n\n```bash\npython3 setup.py sdist\npip3 install gtm_manager --find-links $(pwd)/dist/\n```\n\n## Getting Started\n\nUse a Google account to create application credentials, download the JSON file and put it in the same directory as your script with the name `client_secret.json`. During the first execution of any API-dependent library code, you will be prompted to perform the auth flow.\n\n```python\nfrom gtm_manager import GTMManager\n\naccounts = GTMManager().list_accounts()\n\nfor account in account:\n print(account.name)\n```\n\n## Authentication\n\nThis library currently only supports user-based oauth crendentials. Service accounts can not be used.\n\nWhen using any of the classes from the resources that require loading data from the Google Tag Manager API, the library will look for an existing in OAuth token in the credentials file or prompt the user to authorize which requires a client secret file.\n\n### Client Secrets\n\nThe Google OAuth flows requires you to provide a [client id and secret](https://developers.google.com/api-client-library/python/guide/aaa_client_secrets) in the from of a `JSON` file. You can create these in any Google Cloud or Google Developer project:\n\n> 1. Open the Google API Console Credentials page.\n> 2. From the project drop-down, choose Create a new project, enter a name for the project, and optionally, edit the provided Project ID. Click Create.\n> 3. On the Credentials page, select Create credentials, then select OAuth client ID.\n> 4. You may be prompted to set a product name on the Consent screen; if so, click Configure consent screen, supply the requested information, and click Save to return to the Credentials screen.\n> 5. Select Other for the Application type, and enter any additional information required.\n> 6. Click Create.\n> 7. On the page that appears, you can download client id and secret as a JSON file.\n\nBy default, the `gtm_manager` will look for client id and secret in the file `client_secret.json`. You can overwrite the default to any file name with absolute or relative path:\n\n```python\ngtm_manager.CLIENT_SECRET_FILE = \"my_client_secret.json\"\n```\n\n### Credentials File\n\nOAuth user credentials will be stored in plain text. During every invocation of API-dependent library code, the `gtm_manager` will try to open this file for credentials. If no credentials are present, a new auth flow with the provided client id and secret will be started.\n\nThe auth flow will request _offline_ access from the user providing the script with an oauth refresh token to continue using the file as long as the user not explicitly revokes access.\n\nBy default, the `gtm_manager` will look for existing and store new credentials in the file `auth_credentials.json`. You can overwrite the default to any file name with absolute or relative path:\n\n```python\ngtm_manager.CREDENTIALS_FILE_NAME = \"my_auth_credentials.json\"\n```\n\n### Scopes\n\nThe Google OAuth system uses scopes to request different types of account access from a user. The Google Tag Manager API uses seven different scopes. Different API methods requires different scopes. Details can be found in the [Google Tag Manager API Reference](https://developers.google.com/tag-manager/api/v2/). After initial authorisation, the stored credentials can not extend or chang their scope.\n\nBy default, the `gtm_manager` will request all seven scopes from a user during the auth flow. For ease of use, all scopes are defined as constants under `gtm_manager.GoogleTagManagerScopes`.\n\nYou can overwritte the requested scopes to an array of scope strings:\n\n```python\ngtm_manager.AUTH_SCOPES = [\n gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS,\n gtm_manager.GoogleTagManagerScopes.PUBLISH,\n]\n```\n\n### Auth Best Practice\n\nEven though the default settings get you up and running quickly, it is recommended to always **explicitly** set your settings. Every `gtm_manager` script should therefore contain the following code block:\n\n```python\n# explicitly set the location of your client secret file\ngtm_manager.CLIENT_SECRET_FILE = \"my_client_secret.json\"\n# explicitly set the location of your credentials file\ngtm_manager.CREDENTIALS_FILE_NAME = \"my_auth_credentials.json\"\n# explicitly set the required scopes\ngtm_manager.AUTH_SCOPES = [\n gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS,\n gtm_manager.GoogleTagManagerScopes.PUBLISH,\n]\n```\n\n## Usage Examples\n\nThe `gtm_manager` speeds up interaction working with the Google Tag Manager API for various use cases. Some of these use cases are demoed below. If you are missing a use case, please open an issue and we will be happy to help and extend the demo!\n\n### List all GTM containers in an account\n\n```python\n# import gtm_manager\n# from gtm_manager.manager import GTMManager\n\n# gtm_manager.CLIENT_SECRET_FILE = \"my_client_secret.json\"\n# gtm_manager.CREDENTIALS_FILE_NAME = \"my_auth_credentials.json\"\n# gtm_manager.AUTH_SCOPES = [gtm_manager.GoogleTagManagerScopes.READONLY]\n\naccounts = GTMManager().list_accounts()\n\nfor account in accounts:\n print(account.name)\n```\n\n### Add a new tag, trigger, variable to all containers in an account\n\n```python\n# import gtm_manager\n# from gtm_manager.account import GTMAccount\n\n# gtm_manager.CLIENT_SECRET_FILE = \"my_client_secret.json\"\n# gtm_manager.CREDENTIALS_FILE_NAME = \"my_auth_credentials.json\"\n# gtm_manager.AUTH_SCOPES = [\n# gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS,\n# gtm_manager.GoogleTagManagerScopes.PUBLISH,\n# gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERVERSIONS,\n# ]\n\naccount = GTMAccount(path=\"accounts/1234\")\ncontainers = account.list_containers()\n\nfor container in containers:\n workspace = container.create_workspace(\"Global Update Workspace\")\n\n trigger = workspace.create_trigger(\n {\n \"name\": \"Custom - Generic Event\",\n \"type\": \"CUSTOM_EVENT\",\n \"customEventFilter\": [\n {\n \"type\": \"EQUALS\",\n \"parameter\": [\n {\"type\": \"TEMPLATE\", \"key\": \"arg0\", \"value\": \"{{_event}}\"},\n {\"type\": \"TEMPLATE\", \"key\": \"arg1\", \"value\": \"Generic Event\"},\n ],\n }\n ],\n }\n )\n\n variable = workspace.create_variable(\n {\n \"name\": \"cjs.randomNumber\",\n \"type\": \"jsm\",\n \"parameter\": [\n {\n \"type\": \"TEMPLATE\",\n \"key\": \"javascript\",\n \"value\": \"function() {\\n return Math.random();\\n}\",\n }\n ],\n }\n )\n\n workspace.create_tag(\n {\n \"name\": \"HTML - Hello Log\",\n \"type\": \"html\",\n \"parameter\": [\n {\n \"type\": \"TEMPLATE\",\n \"key\": \"html\",\n \"value\": '',\n }\n ],\n \"firingTriggerId\": [trigger.triggerId],\n }\n )\n\n version = workspace.create_version(\"Global Update Workspace\")\n version.publish()\n```\n\n### Update a Variable on a Tag\n\n```python\n# import gtm_manager\n# from gtm_manager.account import GTMAccount\n\n# gtm_manager.CLIENT_SECRET_FILE = \"my_client_secret.json\"\n# gtm_manager.CREDENTIALS_FILE_NAME = \"my_auth_credentials.json\"\n# gtm_manager.AUTH_SCOPES = [\n# gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERS,\n# gtm_manager.GoogleTagManagerScopes.EDIT_CONTAINERVERSIONS,\n# gtm_manager.GoogleTagManagerScopes.PUBLISH,\n# ]\n\naccount = GTMAccount(path=\"accounts/1985550951\")\ncontainers = account.list_containers()\n\nfor container in containers:\n workspace = container.create_workspace(\"Global Update Workspace\")\n\n tag = workspace.get_tag_by_name(\"UA - Pageview\")\n\n doubleClick_param = tag.parameter_dict[\"doubleClick\"]\n doubleClick_param.value = \"false\"\n\n tag.update(parameter=[doubleClick_param])\n\n version = workspace.create_version(\"Global Update Workspace\")\n version.publish()\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "gtm,google tag manager", "license": "", "maintainer": "", "maintainer_email": "", "name": "gtm-manager", "package_url": "https://pypi.org/project/gtm-manager/", "platform": "", "project_url": "https://pypi.org/project/gtm-manager/", "project_urls": null, "release_url": "https://pypi.org/project/gtm-manager/0.3.0/", "requires_dist": [ "google-auth-oauthlib", "google-auth", "google-api-python-client", "retrying", "ratelimit", "sphinx (>=1.8.2) ; extra == 'docs'", "sphinx-rtd-theme ; extra == 'docs'", "pytest ; extra == 'tests'" ], "requires_python": "", "summary": "An object-oriented helper library wrapping the Tag Manager API Client Library for Python.", "version": "0.3.0" }, "last_serial": 5967074, "releases": { "0.2.1": [ { "comment_text": "", "digests": { "md5": "649b1a31458b0e3f35f2d1a473d9afa8", "sha256": "197bc51cd4d39c9c1c12dbd24b4f5abecafb62107931a55d0bbe311625d9ea0d" }, "downloads": -1, "filename": "gtm_manager-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "649b1a31458b0e3f35f2d1a473d9afa8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 28768, "upload_time": "2018-11-26T13:31:12", "url": "https://files.pythonhosted.org/packages/90/2b/f4ffd2b467e844f44a9581c43f761d2160a0dacced99a34750b7867d34b3/gtm_manager-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9200bea032e896873675307d19b814b", "sha256": "0c9b02f012cd12bd860d1ee181d07cc4f3526b90d21674820fc4d360cf5053e3" }, "downloads": -1, "filename": "gtm-manager-0.2.1.tar.gz", "has_sig": false, "md5_digest": "c9200bea032e896873675307d19b814b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24241, "upload_time": "2018-11-26T13:31:14", "url": "https://files.pythonhosted.org/packages/21/b6/0779de6471e2acb21ad09e3d4a30ac9f8bb237b404cf01fa19f949b2a664/gtm-manager-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "434eaafd5fef9323ea750c1752ad2edc", "sha256": "f98f8b3898f78bb1fc159825a6233af04d3468c76e6c5ed54ce832a2055157c0" }, "downloads": -1, "filename": "gtm_manager-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "434eaafd5fef9323ea750c1752ad2edc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 29006, "upload_time": "2018-11-26T21:35:11", "url": "https://files.pythonhosted.org/packages/49/69/c9154973837e995ff95e96427475e2463f8530e7c77ffa987f03e5a088a4/gtm_manager-0.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a43b45bd38a438ebe691672d1be30fbc", "sha256": "ca22bf9c1189ccabe1f6b3a1683151cfce336c6faa0c3b44ea7301b6b5159744" }, "downloads": -1, "filename": "gtm-manager-0.2.2.tar.gz", "has_sig": false, "md5_digest": "a43b45bd38a438ebe691672d1be30fbc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19314, "upload_time": "2018-11-26T21:35:12", "url": "https://files.pythonhosted.org/packages/6f/89/1a1beb8e0ff85101d422e9df07677c3a7e108b50f989a7291235ffcb927e/gtm-manager-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "8774ad0f206357b2e3d021f661cc2475", "sha256": "11bc45d4a55e69a4548a84b581bff38a918443af0189f463a3ce06bdcca99b34" }, "downloads": -1, "filename": "gtm_manager-0.2.3-py3-none-any.whl", "has_sig": false, "md5_digest": "8774ad0f206357b2e3d021f661cc2475", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 29038, "upload_time": "2019-07-16T14:26:43", "url": "https://files.pythonhosted.org/packages/9d/4c/695a27ec8916c81ace183a04663379ea1bc6ea1cbd29a13ff52fcadc1f30/gtm_manager-0.2.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a177170ca4d40d22c3eb28e327a3fa9d", "sha256": "4c531ad3a29317552a54bbfa123155fe8f2df37b096b74ecb946c6c55f2ed3d3" }, "downloads": -1, "filename": "gtm-manager-0.2.3.tar.gz", "has_sig": false, "md5_digest": "a177170ca4d40d22c3eb28e327a3fa9d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19346, "upload_time": "2019-07-16T14:26:44", "url": "https://files.pythonhosted.org/packages/03/e6/8134cde001baf4b71858c4eb5ecd7aeeb4119fea29e65bcb651dad37ac1b/gtm-manager-0.2.3.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "2b34ae7b5f5193b97f8b90645ef8c920", "sha256": "8e1de28ec5abb82cc2c472945eb0c3246b6d7039de4d2e376245ec2d63b715d8" }, "downloads": -1, "filename": "gtm_manager-0.2.5-py3-none-any.whl", "has_sig": false, "md5_digest": "2b34ae7b5f5193b97f8b90645ef8c920", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 29066, "upload_time": "2019-08-22T20:50:53", "url": "https://files.pythonhosted.org/packages/a1/80/d459ce4e5905b0c52c71d5b70d24d746e545721d3eb8a706147a6b9eb99d/gtm_manager-0.2.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "738b15238d1a8945b6ad1874c065e912", "sha256": "7bee3f44f7014bff9696bca2d8afc72dc5f483b1cd41853ae971b4d155644645" }, "downloads": -1, "filename": "gtm-manager-0.2.5.tar.gz", "has_sig": false, "md5_digest": "738b15238d1a8945b6ad1874c065e912", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19347, "upload_time": "2019-08-22T20:50:54", "url": "https://files.pythonhosted.org/packages/25/bc/35bb8df9ee9eccc98f8f2768840c25eb5aca324391a5eecc2b2e61751f54/gtm-manager-0.2.5.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "17b440cf9b6e8932093bb14e231854fc", "sha256": "389fed6b4d34f91eb3ee55fa315335211de0b29a5ad3d9cdb24e430379651ad0" }, "downloads": -1, "filename": "gtm_manager-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "17b440cf9b6e8932093bb14e231854fc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 29100, "upload_time": "2019-10-13T10:45:41", "url": "https://files.pythonhosted.org/packages/96/11/a42b72ce5727b2616844b4b61e2077e0558680a36c5e92757c4f20a7ae7f/gtm_manager-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05137c41801f9a25326aa4d1af46cb55", "sha256": "59b27964861ce7caf932d5fb6656d484c0fe49bc2ed7465bc828eed2e94779f5" }, "downloads": -1, "filename": "gtm-manager-0.3.0.tar.gz", "has_sig": false, "md5_digest": "05137c41801f9a25326aa4d1af46cb55", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19369, "upload_time": "2019-10-13T10:45:43", "url": "https://files.pythonhosted.org/packages/4b/a5/be2c29fbc5eb77d760721fe4597a8bf138f5efbec9f130f5041ff1d4e161/gtm-manager-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "17b440cf9b6e8932093bb14e231854fc", "sha256": "389fed6b4d34f91eb3ee55fa315335211de0b29a5ad3d9cdb24e430379651ad0" }, "downloads": -1, "filename": "gtm_manager-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "17b440cf9b6e8932093bb14e231854fc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 29100, "upload_time": "2019-10-13T10:45:41", "url": "https://files.pythonhosted.org/packages/96/11/a42b72ce5727b2616844b4b61e2077e0558680a36c5e92757c4f20a7ae7f/gtm_manager-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05137c41801f9a25326aa4d1af46cb55", "sha256": "59b27964861ce7caf932d5fb6656d484c0fe49bc2ed7465bc828eed2e94779f5" }, "downloads": -1, "filename": "gtm-manager-0.3.0.tar.gz", "has_sig": false, "md5_digest": "05137c41801f9a25326aa4d1af46cb55", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19369, "upload_time": "2019-10-13T10:45:43", "url": "https://files.pythonhosted.org/packages/4b/a5/be2c29fbc5eb77d760721fe4597a8bf138f5efbec9f130f5041ff1d4e161/gtm-manager-0.3.0.tar.gz" } ] }