Python implementation of the Piwik HTTP API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Johann Schmitz 5a1cccb382
Use build_absolute_uri if available to populate the url property
4 years ago
src/pypiwik Use build_absolute_uri if available to populate the url property 4 years ago
tests Fixed tests 4 years ago
.gitignore Auxiliary files 4 years ago
LICENSE.txt Added license 4 years ago
Makefile Updated coverage arguments 4 years ago Updated README 4 years ago
requirements.txt Auxiliary files 4 years ago
requirements_dev.txt Auxiliary files 4 years ago Fixed 4 years ago

Python implementation of the Piwik HTTP API


Basic usage:

from pypiwik.tracker import PiwikTracker
tracker = PiwikTracker('', 1)

now you can call


to make a server-to-server tracking request, or call


to generate the correct Javascript snippet.

Tracking variables

Tracking variables are set as class attributes on the tracker object. Have a look at the pypiwik.tracker.PARAMETERS dictionary to see which attribute maps to which tracking parameter, e.g.:

tracker = PiwikTracker('', 1)
tracker.action_name = 'Help / Support'

You can also pass the tracking variables to the track_page_view or tracking_code call as kwargs. The code above is equivalent to the following:

tracker = PiwikTracker('', 1)
tracker.track_page_view(action_name='Help / Support')

Custom variables

Custom variables can be set in the page_custom_vars and visit_custom_vars dictionary to track custom variables in the page and visit scope:

Note: Piwik allows at most 5 custom variables per scope. When making server-to-server requests, the code does not check for the numbers of variables in the dictionary.

Server API

When making server-to-server calls, pypiwik will use HTTP headers for the following variables to reduce the request size:

  • user_agent
  • referer
  • lang

If you want to pass the values as regular variables, set spoof_request to False on the tracker instance.

Cloning another request

If you want to make server-to-server requests based on a HTTP request of an actual user, pass the request object to __init__:

tracker = PiwikTracker('', 1, request)

Note: atm, only Django-like request objects supported (an object which has a META dictionary).