Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

GoodRx/universal-analytics-python

 
 

Repository files navigation

Universal Analytics for Python

This library provides a Python interface to Google Analytics, supporting the Universal Analytics Measurement Protocol, with an interface modeled (loosely) after Google's analytics.js.

Service Status
CircleCI CircleCI

Usage

A simple example:

from UniversalAnalytics import Tracker

tracker = Tracker.create('UA-XXXXX-Y', client_id = CUSTOMER_UNIQUE_ID)
tracker.send('event', 'Subscription', 'billing')

Please see the test/test_everything.py script for additional examples.

This library support the following tracking types, with corresponding (optional) arguments:

  • pageview: [ page path ]
  • event: category, action, [ label [, value ] ]
  • social: network, action [, target ]
  • timing: category, variable, time [, label ]

Additional tracking types supported with property dictionaries:

  • transaction
  • item
  • screenview
  • exception

Property dictionaries permit the same naming conventions given in the analytics.js Field Reference, with the addition of common spelling variations, abbreviations, and hyphenated names (rather than camel-case). These are also demonstrated in the tests/main.py file.

Further, the property dictionaries support names as per the Measurement Protocol Parameter Reference, and properties/parameters can be passed as named arguments.

Example:

  # as python named-arguments
  tracker.send('pageview', path = "/test", title = "Test page")

  # as property dictionary
  tracker.send('pageview', {
    'path': "/test",
    'title': "Test page"
  })

Attribution

This package is a fork of a package by the same name by Analytics Pros.

License

universal-analytics-python is licensed under the BSD license

Packages

No packages published

Languages

  • Python 94.9%
  • Makefile 5.1%