Python implementation of the Piwik HTTP API.
Note: This project is called python-piwik on PyPI since pypiwik is already taken by an abandoned project.
from pypiwik.tracker import PiwikTracker tracker = PiwikTracker('http://example.com', 1)
now you can call
to make a server-to-server tracking request, or call
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('http://example.com', 1) tracker.action_name = 'Help / Support' tracker.track_page_view()
You can also pass the tracking variables to the
tracking_code call as kwargs. The code above is equivalent to the following:
tracker = PiwikTracker('http://example.com', 1) tracker.track_page_view(action_name='Help / Support')
Custom variables can be set in the
visit_custom_vars dictionary to track custom variables in the
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.
When making server-to-server calls,
pypiwik will use HTTP headers for the following variables to reduce the request size:
If you want to pass the values as regular variables, set
False on the tracker instance.
If you want to make server-to-server requests based on a HTTP request of an actual user, pass the request object to
tracker = PiwikTracker('http://example.com', 1, request)
Note: atm, only Django-like request objects supported (an object which has a