How do I track a PYPI project using Google Analytics?

I want to track my pypi project using Google Analytics. I was wondering where exactly should I include the Google Analytics code?

+3


source to share


2 answers


It is best to use Measurement Log to send clicks. If you can send an HTTP request using the requests module:

pip install requests

      

You can use something similar to the example below with your own tracking ID and parameters.



import requests

payload = {'v': '1',                # Version.
           'tid': 'UA-XXXXX-1',     # Tracking ID / Property ID.
           'cid': '123456',         # Anonymous Client ID.
           'dh': 'www.example.com', # Document hostname.
           'dp': 'home',            # Page.
           't': 'pageview'          # Hit Type.
          }

requests.post('http://www.google-analytics.com/collect', payload)

      

Just make sure the code runs during any given event that you want to monitor.

+1


source


Unable to include Google Analytics code for a project in PyPI. However, you can include it on the project website (if any) and other pages related to the project, such as documentation.



+1


source







All Articles