Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Python Tracking API and Analytics API clients #3079

anonymous-piwik-user opened this Issue · 16 comments

2 participants


Hi. I've written a simplified python tracking API class. It was written for a client so I have only implemented a subset of the features, and the class is Django-specific. But the code should be reasonably easy to extend and port if anybody else needs it.

The code is at

Seems to work for me so far but some more testing is needed.
Keywords: third-party-plugin


Btw, at the moment the work is happening on the more_features branch if anybody is looking at this. I have started the work to support more features and have dropped the Django dependency.


The project was renamed and moved:

The Django dependency is gone.


Oh well, only implementing the tracking API didn't make much sense as it's not possible to verify in unit tests that the data was submitted properly. So I have started to implement the analytics API as well and renamed the project again to reflect the new scope. Certainly the last time.



Still in alpha.

Btw, could somebody remove both keywords and add Python Piwi API or somesuch?


nkuttler, really well done! excellent work...

Currently we offiially advertise the PHP and Java Analytics API on the Tracking API doc page. Also in our recent blog post from yesterday we only mention php/java API: Mobile app analytics

Is the Python Tracking API stable? would you feel confident advertising it on the website tracking api page? Thanks!


Thanks matt!

The tracking API is pretty stable. With today's push to github everything that doesn't involve cookies should be implemented and unit tested, but I'll have to check that again once I decide how to test the session stuff.

I think it's ok to advertise the tracking API as more testers would be good. I hope to make a 0.2 release this or next week with complete unit testing and docs for the tracking API. Then it will be ready for the official tracking API doc page.


Let me know when you're happy with your code and i'll update the page. Then more users will be able to find it. We can also announce it on the blog and changelog for the next release.

  • great to hear you are writing tests for it :) what is your strategy for tests?
  • would you consider committing the code to Piwik SVN in the future?
  • can you please put all the code under BSD license?



Will do!

I have a few tests for the classes themselves, exceptions etc. Most of the tests check that the submitted data was received by Piwik, either by checking the debug output or by querying the analytics API.

I think I'll refactor the debug parsing to query the API as well, that seems better. Probably not for the release though.

Of course the code can be added to SVN. Development should be done on git/github though, I guess I'll document that just in case.

The code is already licensed as BSD :-)


I'm a little confused with cookie handling in the PHP tracking API. There are methods like setCustomVariable() that I would have expected to set cookies, or that Piwik would set the cookies when I do the tracking request. However, it seems like it assumes that cookies are always set through JS? Just wondering what the point of setCustomVariable() in PHP is then?

Or maybe there's a better place to ask if I have generic API questions?


Replying to nkuttler:

I'm a little confused..

Oh my I guess I should go out... Piwik would recognize if the custom variables were set through cookies, and setCustomVariable() in PHP is just to submit them manually as the server has no cookies, right? Anyway... will look into this over the weekend :)


Piwik would recognize if the custom variables were set through cookies, and setCustomVariable() in PHP is just to submit them manually as the server has no cookies, right?

Yes correct, the PHP client does not set /forward first party cookies, but it will read the existing javascript cookie if any was set by javascript for this user.


Thanks matt!

I've made a 0.2 release, but the cookie stuff didn't make it in. I consider this an alpha release and am pushing the code to a few live sites to test it there. I've already found a few things I'd like to add/change before an official announcement. I'll keep you posted.


Please let me know when the API is stable, and we could list it on the new page Piwik integration plugins & libraries


Hi matt, the code is being used by more people now so I consider the API stable for now. Feel free to list my code anywhere you like.


Great news. Thank you for your contrib and work!

The Python Tracking API and Analytics API client is now listed on: and also on:

Kuddos for your work!


I can confirm it is still listed at

Hope your library is getting more users and that it works well. Keep up the good work!

@mattab mattab added the R: worksforme label
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.