This page contains the API Reference for the Piwik Tracking API. This REST API allows to record Visitor and Events data in Piwik using any programming language. This Tracking API is different from the Analytics API.
Note: This doc is aimed at developers who are not using Javascript, PHP or Java. For JS, PHP and Java languages, there is already a client available. See the main documentation about Piwik Tracking API.
To track page views, events, visits, you have to send a HTTP request to your Tracking REST API endpoint: http://your-piwik-domain.tld/piwik.php
This section explains the various HTTP GET parameters that you can set to the Tracking API request to ensure your data is as complete and useful as possible. Some of these fields will not be available in your app / software which is expected: only a few parameters are required.
Note: all parameters values that are strings (such as ‘url’, ‘action_name’, etc.) must be URL encoded.
Specifying any of the user’s Geo location details requires token_auth to be set:
Note about tracking bots
By default Piwik does not track bots. If you use the REST Tracking API, you might want to also enable tracking of these requests that Piwik detect as both (using basic user agent matching or IPs from known bots). To enable Bot Tracking in Piwik, set the parameter &bots=1 to the piwik.php request.
Here is an example of a real tracking request, as done by Piwik Mobile app for the anonymous Piwik Mobile Analytics.
http://piwik-server/piwik.php?_cvar={“1″:["OS","iphone 5.0"],”2″:["Piwik Mobile Version","1.6.2"],”3″:["Locale","en::en"],”4″:["Num Accounts","2"]}&action_name=View settings&url=http://mobileapp.piwik.org/window/settings &idsite=8876&rand=351459&h=18&m=13&s=3 &rec=1&apiv=1&cookie= &urlref=http://iphone.mobileapp.piwik.org&_id=af344a398df83874 &_idvc=19&res=320×480&
Explanation: this URL has custom variables for the OS, Piwik version, # Accounts created, tracks an event “View settings” with a fake URL, records the screen resolution, and also includes _id, a custom unique ID generated to ensure all requests for the same Mobile App user will be recorded for the same visit in Piwik.
To verify that your data is being tracked properly, you can enable debug logging in the Piwik tracking file piwik.php.
Tracking requests will then output the tracking logs rather than displaying a 1*1 transparent GIF beacon.
Follow these simple steps to enable debug logging in piwik.php:
$GLOBALS['PIWIK_TRACKER_DEBUG'] = true;What is Bulk Tracking?
Some applications such as the Piwik log importer, have to track many visits, sometimes tens, hundreds, thousands or even more all at once. Tracking these requests with one HTTP request per visit or action can result in enormous delays because there is a delay of several milliseconds to establish the HTTP connection. Using the bulk tracking feature, however, these requests can be sent all at once as a POST request, making your application far more efficient.
How to Track several pages with one request?
To send a bulk tracking request, you must POST a JSON object to the Piwik tracking endpoint. The object should contain the following properties:
Example Data
{
"requests": [
"?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1",
"?idsite=1&url=http://example.net/test.htm&action_name=Another bul k page view&rec=1"
],
"token_auth": "33dc3f2536d3025974cccb4b4d2d98f4"
}
Example Bulk Tracking Call using CURL
Here is an example POST request passing the JSON containing the token and the requests.
$ curl -i -X POST -d '{"requests":["?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1","?idsite=1&url=http://example.net/test.htm&action_name=Another bul
k page view&rec=1"],"token_auth":"33dc3f2536d3025974cccb4b4d2d98f4"}' http://piwik.example.com/piwik.php
#This will track 2 requests using only 1 http request to Piwik.
More information
See the doc about Piwik Tracking API for more information. If you’re stuck, ask in the forums (after making a search) or hire a Piwik expert.
If you have any feedback or suggestion about this doc let us know in the comment field below.
Feedback on this page
Have you found an error in this page, or do you think some information is missing or not clear? We appreciate you taking the time to send us your suggestions and feedback on this page.