• Stars
    star
    107
  • Rank 321,924 (Top 7 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Universal Analytics Python module

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.

NOTE this project is reasonably feature-complete for most use-cases, covering all relevant features of the Measurement Protocol, however we still consider it beta. Please feel free to file issues for feature requests.

Contact

Email: [email protected]

Installation

The easiest way to install universal-analytics is directly from PyPi using pip by running the following command:

pip install universal-analytics-python

Or use latest code:

pip install -e git+https://github.com/analytics-pros/universal-analytics-python.git#egg=universal-analytics-python-dev

Otherwise you can download source code and install it directly:

python setup.py install

Usage

For the most accurate data in your reports, Analytics Pros recommends establishing a distinct ID for each of your users, and integrating that ID on your front-end web tracking, as well as back-end tracking calls. This provides for a consistent, correct representation of user engagement, without skewing overall visit metrics (and others).

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"
  })

Features not implemented

  • Throttling

We're particularly interested in the scope of throttling for back-end tracking for users who have a defined use-case for it. Please contact us if you have such a use-case.

License

universal-analytics-python is licensed under the BSD license

More Repositories

1

Swift-GA-Tracker-for-Apple-tvOS

Google Analytics tracker for Apple tvOS provides an easy integration of Google Analyticsโ€™ measurement protocol for Apple TV.
Swift
81
star
2

GA4-Measurement-Protocol-Python

Google Analytics 4 Python Library for Measurement Protocol
Python
57
star
3

universal-analytics-php

Universal Analytics library for PHP
PHP
48
star
4

google_analytics_flattener_ga4

Python
39
star
5

GA4-bigquery-tips

Helpful queries on top of the GA4 BigQuery export. Content in here follows Adswerve's GA4 bigquery tips blog posts.
36
star
6

GA4-Measurement-Protocol-Typescript

Google Analytics 4 Measurement Protocol library downloadable on NPM
TypeScript
26
star
7

universal-analytics-c

Universal Analytics in C
C
17
star
8

google_analytics_flattener

Google Cloud Platform solution that provides an event driven process that flattens (unnests) Google Analytics 360 data that has been exported to BigQuery.
Python
16
star
9

GA4-Measurement-Protocol-Apple-tvOS

Enables Apple TV (tvOS) apps to send Google Analytics events and user properties to "Google Analytics 4" properties (formerly App+Web).
Swift
8
star
10

ga4-data-api-and-ua-reporting-api-quickstart-demo

This repo has code snippets to get you started with Reporting API v4 (UA) and Data API (GA4)
Python
5
star
11

firebase-google-analytics-helper

Sample code for an "AnalyticsHelper" class in Java, Kotlin, Swift, and Objective-C to assist with common analytics implementation needs when using Firebase and Google Analytics.
Objective-C
3
star
12

Objective-C-GA-Tracker-for-Apple-tvOS

Objective-C
2
star
13

GTM-Function-Call-Analytics-Variable-Provider

Sample implementation of an "AnalyticsVariableProvider" class that returns requested values to Google Tag Manager (v5) for apps via Function Call variables.
Objective-C
2
star
14

google_analytics_and_adwords

PHP
1
star
15

Kubeflow-Pipelines-Samples

Sample Kubeflow Pipelines to get you started.
Jupyter Notebook
1
star