views:

256

answers:

2

I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire webbrowser component just to send a javascript request?

+3  A: 

There's a question for this in SO, Generate Google Analytics events (__utm.gif requests) serverside.

The problem is:

it seems like it's a little old and there's no documentation of how to log events, only page views.

...and you want to track events instead of page views.

When searching "server side google analytics" in google, you find the same sources presented in SO question as the more relevant ones. There is a lib though in php named Server Side Google Analytics to do it. The last commit is from Apr 28 2009, so I dont know if it's working or if it's possible to track events (and it's in php, not Python).

I know that there's an official google analytics traking solution without javascript (also check the release note from their blog) for mobile applications, and it even comes with a php library. Maybe you can "fool" their service and act like your application is a mobile one to track your events, rewriting this lib in Python? (I don't know if this violates Google's TOS, you should read it just in case).

IMHO, if google analytics is really the only way you want to do what you want and everything fails, I would try to use a webbrowser component.

As a last resource, you can try to create a simple analytics tool to track your api usage using google's documentation.

(If you think none of these suggestions are useful, I would try to search "google analytics without javascript" on google. Good luck!)

GmonC
+2  A: 

There is an open source implementation of Google-Analytics for Mobile in python available here: http://github.com/b1tr0t/Google-Analytics-for-Mobile--python-

You can probably integrate this into your own setup by importing 'track_page_view' and providing it with the appropriate WSGI request environment.

jbochi