{ "info": { "author": "Oliver Marks", "author_email": "oly@digitaloctave.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "#+TITLE: Python google analytics library\n\n* Introduction\nThis library is a simple server side implementation of google analytics it is based on the documentation here.\nhttps://developers.google.com/analytics/devguides/collection/protocol/v1/devguide\n\nIt uses the requests library to send requests directly to google with out any javascript which may be blocked client side.\n\n* Installation\n#+BEGIN_SRC shell :results silent\npip install pygass\n#+END_SRC\n\nThe code is also available at this location for bug fixes or to pull from master.\nhttps://gitlab.com/python-open-source-library-collection/pygass\n\n* Development\nWhen testing its usefull to use the analytics hit builder to check the correct format.\nhttps://ga-dev-tools.appspot.com/hit-builder/\n* Examples\n** Simple Page tracking event\n\nThe below example sends a page view event to google, you will need to provide an anonymous client id and the page url as a minimum.\n\n#+NAME: Page tracking example\n#+BEGIN_SRC python :results output code :exports code\n import random\n import pprint\n import constants as st\n import pygass as an\n\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_pageview(client_id=123, page=\"/test/client/pageview\"), width=1\n )\n#+END_SRC\n\n#+RESULTS: Page tracking example\n#+BEGIN_SRC python\n{'hitParsingResult': [{'hit': '/debug/collect?v=1&tid=UA-10000000-1&cid=123&t=pageview&dp=%2Ftest%2Fclient%2Fpageview',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+END_SRC\n\n\nThe below example demonstrates how to track a transaction with analytics, you will need to send an anonymous client id with the requests.\n\n** Simple transaction tracking event\n\n#+NAME: Transaction tracking example\n#+BEGIN_SRC python :results output code :exports code\n import random\n import pprint\n import constants as st\n import pygass as an\n\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n transaction_id = random.randint(1, 10000000)\n an.track_transaction(client_id=1001, transaction_id=transaction_id)\n pprint.pprint(\n an.track_item(\n client_id=1001, transaction_id=transaction_id, name=\"Test Product 3\"\n ),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Transaction tracking example\n#+BEGIN_SRC python\n{'hitParsingResult': [{'hit': '/debug/collect?v=1&tid=UA-10000000-1&cid=1001&t=item&ti=4801535&in=Test+Product+3&iq=1',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+END_SRC\n** Simple enhanced ecommerce impression\n#+NAME: Enhanced impression ecommerce\n#+BEGIN_SRC python :results output code :exports code\n import random\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n transaction_id = random.randint(1, 10000000)\n pprint.pprint(\n an.track_enhanced_ecommerce_impression(\n client_id=1001, product_id=1001, product_name=\"Test Product 3\", page=\"/test/client/pageview\"\n ),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced impression ecommerce\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?il1pi1id=1001&il1pi1nm=Test+Product+3&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fclient%2Fpageview',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n** Simple enhanced ecommerce action\n#+NAME: Enhanced action ecommerce\n#+BEGIN_SRC python :results output code :exports code\n import random\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_action(\n client_id=1001,\n category=\"cat01\",\n action=\"view\",\n product_id=1337,\n product_name=\"Test Product 3\",\n product_action=\"detail\",\n product_category= \"Product Test Category\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced action ecommerce\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=detail&pr1id=1337&pr1nm=Test+Product+3&pr1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n** Simple enhanced ecommerce view product\n#+NAME: Enhanced ecommerce view product\n#+BEGIN_SRC python :results output code :exports code\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_impression(\n client_id=1001,\n category=\"cat01\",\n action=\"click\",\n product_action=\"add\",\n product_id=1001,\n product_name=\"Test Product 3\",\n product_category=\"Product Test Category\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\nv=1&t=pageview&tid=UA-10000000-1&cid=555&dh=mydemo.com&dp=%2Fhome&dt=homepage\n\n&il1nm=Search%20Results&il1pi1id=P12345&il1pi1nm=Android%20Warhol%20T-Shirt&il1pi1ca=Apparel%2FT-Shirts&il1pi1br=Google&il1pi1va=Black&il1pi1ps=1&il1pi1cd1=Member&il2nm=Recommended%20Products&il2pi1nm=Yellow%20T-Shirt&il2pi2nm=Red%20T-Shirt\n#+RESULTS: Enhanced ecommerce view product\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?il1pi1id=1001&il1pi1nm=Test+Product+3&il1pi1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n** Simple enhanced ecommerce product add to basket\n#+NAME: Enhanced ecommerce product add to basket\n#+BEGIN_SRC python :results output code :exports code\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_add_to_basket(\n client_id=1001,\n category=\"cat01\",\n action=\"click\",\n transaction_id=20,\n product_id=1001,\n product_name=\"Test Product 3\",\n product_category=\"Product Test Category\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced ecommerce product add to basket\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=add&pr1id=1001&pr1nm=Test+Product+3&pr1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage&ti=20',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n** Simple enhanced ecommerce product purchase checkout\n#+NAME: Enhanced ecommerce product checkout\n#+BEGIN_SRC python :results output code :exports code\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_checkout(\n client_id=1001,\n category=\"cat01\",\n action=\"click\",\n transaction_id=20,\n product_id=1001,\n product_name=\"Test Product 3\",\n product_category=\"Product Test Category\",\n product_action=\"purchase\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced ecommerce product checkout\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=add&pr1id=1001&pr1nm=Test+Product+3&pr1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage&ti=20',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n#+NAME: Enhanced ecommerce product add cart\n#+BEGIN_SRC python :results output code :exports code\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_add_to_cart(\n client_id=1001,\n category=\"cat01\",\n action=\"click\",\n transaction_id=21,\n product_id=1001,\n product_name=\"Test Product 3\",\n product_category=\"Product Test Category\",\n product_action=\"add\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced ecommerce product add cart\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=add&pr1id=1001&pr1nm=Test+Product+3&pr1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage&ti=21',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n** Simple enhanced ecommerce product purchase transaction\n#+NAME: Enhanced ecommerce product purchase\n#+BEGIN_SRC python :results output code :exports code\n import pprint\n import pygass.constants as st\n import pygass.enhanced_ecommerce as an\n # set your analytics code\n st.ANALYTICS_CODE = \"UA-10000000-1\"\n\n # use the test api for json responses\n st.ANALYTICS_URL = \"https://www.google-analytics.com/debug/collect\"\n\n # show the response\n pprint.pprint(\n an.track_enhanced_ecommerce_purchase(\n client_id=1001,\n category=\"cat01\",\n action=\"click\",\n transaction_id=20,\n product_id=1001,\n product_name=\"Test Product 3\",\n product_category=\"Product Test Category\",\n product_action=\"purchase\",\n affiliation= \"Test Merchant\",\n revenue= \"0.0\",\n page=\"/test/page\"),\n width=1,\n )\n#+END_SRC\n\n#+RESULTS: Enhanced ecommerce product purchase\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=purchase&pr1id=1001&pr1nm=Test+Product+3&pr1ca=Product+Test+Category&v=1&tid=UA-10000000-1&cid=1001&t=pageview&dp=%2Ftest%2Fpage&ti=20&ta=Test+Merchant&tr=0.0',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src\n\n#+RESULTS:\n: None\n\n#+RESULTS: Enhanced ecommerce add to cart example\n#+begin_src python\n{'hitParsingResult': [{'hit': '/debug/collect?pa=add&pr1id=1001&pr1nm=Test+Product+3&v=1&tid=UA-10000000-1&cid=1001&t=event&ec=cat01&ea=click',\n 'parserMessage': [],\n 'valid': True}],\n 'parserMessage': [{'description': 'Found '\n '1 '\n 'hit '\n 'in '\n 'the '\n 'request.',\n 'messageType': 'INFO'}]}\n#+end_src", "description_content_type": "text/plain", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/python-open-source-library-collection/pygass", "keywords": "google analytics server side", "license": "GPL-3", "maintainer": "", "maintainer_email": "", "name": "pygass", "package_url": "https://pypi.org/project/pygass/", "platform": "", "project_url": "https://pypi.org/project/pygass/", "project_urls": { "Homepage": "https://gitlab.com/python-open-source-library-collection/pygass" }, "release_url": "https://pypi.org/project/pygass/0.2.10/", "requires_dist": null, "requires_python": "", "summary": "Server side implementation of Google Analytics in Python.", "version": "0.2.10" }, "last_serial": 5371859, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "2a51d80561cb2f892a858418f5fcbe0e", "sha256": "231ae4d16580ee348cd9d40e016fa6f87907d94291a4e622a836ca62940fc02f" }, "downloads": -1, "filename": "pygass-0.1.2.tar.gz", "has_sig": false, "md5_digest": "2a51d80561cb2f892a858418f5fcbe0e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5033, "upload_time": "2018-09-25T18:33:31", "url": "https://files.pythonhosted.org/packages/58/b3/ee14dbf5275e4fb0faa71a5548fbd656c39481d4ae8e48fc1cf639d792d4/pygass-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "c9a4ccec3a0bef32f7622ce801fdff02", "sha256": "dbc94fffe22444450b66f36a8cfc0c1c1703c3b6f3cd27b2573d60263342f3ce" }, "downloads": -1, "filename": "pygass-0.1.3.tar.gz", "has_sig": false, "md5_digest": "c9a4ccec3a0bef32f7622ce801fdff02", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5538, "upload_time": "2018-10-08T20:16:27", "url": "https://files.pythonhosted.org/packages/13/94/27e8b79379ce063709375089b08190022c5a85679353c6d43d1c11441d88/pygass-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "494786c8fcccddca26226510fc164937", "sha256": "33dbb545936f67b19db8417d614682e86d47603579ccad58be1d76428eebb300" }, "downloads": -1, "filename": "pygass-0.1.4.tar.gz", "has_sig": false, "md5_digest": "494786c8fcccddca26226510fc164937", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5523, "upload_time": "2018-10-16T19:38:43", "url": "https://files.pythonhosted.org/packages/67/be/caed3221375d09f12f0c76b421115bca5866a69db816a39b68fdf66856c3/pygass-0.1.4.tar.gz" } ], "0.2.10": [ { "comment_text": "", "digests": { "md5": "4257892eaa2ce08e92bbab52d4b1d50f", "sha256": "b68dcbd418a257d2190e720ae0140ca3dc509d7c21fdafe0d24bf793caedaf7f" }, "downloads": -1, "filename": "pygass-0.2.10.tar.gz", "has_sig": false, "md5_digest": "4257892eaa2ce08e92bbab52d4b1d50f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9749, "upload_time": "2019-06-07T14:38:12", "url": "https://files.pythonhosted.org/packages/e0/e2/8a66a3d18100a797489afb9757c3fd01a7741c35308351f8c35c8862d773/pygass-0.2.10.tar.gz" } ], "0.2.6": [ { "comment_text": "", "digests": { "md5": "17d95e13d03272056703d994dc01ace1", "sha256": "cc601848ff0527c98b0ce8eaa8e426baebfbc82712f9ff61b5daebd7d6353795" }, "downloads": -1, "filename": "pygass-0.2.6.tar.gz", "has_sig": false, "md5_digest": "17d95e13d03272056703d994dc01ace1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10670, "upload_time": "2019-04-28T20:19:40", "url": "https://files.pythonhosted.org/packages/66/b9/50fbdf720c753a6e04f692185692700e43d896d0465c3fd9965343350180/pygass-0.2.6.tar.gz" } ], "0.2.7": [ { "comment_text": "", "digests": { "md5": "04353a7f1bd065e7b77da6ec00591ab3", "sha256": "75cf91a721118411a6e1be01cc318520adb992960aeb6bad14c394cd99f0d8ae" }, "downloads": -1, "filename": "pygass-0.2.7.tar.gz", "has_sig": false, "md5_digest": "04353a7f1bd065e7b77da6ec00591ab3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8332, "upload_time": "2019-05-23T14:41:40", "url": "https://files.pythonhosted.org/packages/eb/4b/62dae5f772c71e9a8d531037ab3854f242464a5a3854bc39dce8ef97c770/pygass-0.2.7.tar.gz" } ], "0.2.8": [ { "comment_text": "", "digests": { "md5": "b56a2e31025ce3c6cf3dfb292c029194", "sha256": "d9845b8a6f6dbdc7c0525b6a0504ca86e96cba0e392420838da1db41a0de82d7" }, "downloads": -1, "filename": "pygass-0.2.8.tar.gz", "has_sig": false, "md5_digest": "b56a2e31025ce3c6cf3dfb292c029194", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9303, "upload_time": "2019-05-23T14:56:55", "url": "https://files.pythonhosted.org/packages/7e/5e/47ea98981f48357857e9e33408528888e4a930dd2d6de0e33ece3f5ad600/pygass-0.2.8.tar.gz" } ], "0.2.9": [ { "comment_text": "", "digests": { "md5": "b3a71688f180ea28b2d5939cc2e4c17f", "sha256": "47ecc0ceec4db2c452795a317d1b4b399ef759876e8757419d37462746d54cbd" }, "downloads": -1, "filename": "pygass-0.2.9.tar.gz", "has_sig": false, "md5_digest": "b3a71688f180ea28b2d5939cc2e4c17f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9305, "upload_time": "2019-05-24T15:29:35", "url": "https://files.pythonhosted.org/packages/65/92/78c6a66fc876f0923f763e859cc2bf0a9caaaa83fa03b3a732161fcc8dec/pygass-0.2.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4257892eaa2ce08e92bbab52d4b1d50f", "sha256": "b68dcbd418a257d2190e720ae0140ca3dc509d7c21fdafe0d24bf793caedaf7f" }, "downloads": -1, "filename": "pygass-0.2.10.tar.gz", "has_sig": false, "md5_digest": "4257892eaa2ce08e92bbab52d4b1d50f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9749, "upload_time": "2019-06-07T14:38:12", "url": "https://files.pythonhosted.org/packages/e0/e2/8a66a3d18100a797489afb9757c3fd01a7741c35308351f8c35c8862d773/pygass-0.2.10.tar.gz" } ] }