TheMethod
TheMethod

Reputation: 3001

REST service Google Analytics integration

I have a REST service implemented using django-rest-framework. What I would like to do is start recording Google Analytics data (events for starters) when particular requests are made.

I've done some looking around, I see there is a Google Analytics python library , but from what I can see it's more for querying the API and not posting to it. I see there is a py-ga library but it hasn't been updated in awhile. Seems other libraries for django and analytics are meant to be used client side via JavaScript.

What would be a reasonable way to implement what I am looking for? Am I missing an official library somewhere? Anyone have any experience doing this? Any advice would be appreciated, thanks much!

Upvotes: 2

Views: 1098

Answers (1)

grrrrrr
grrrrrr

Reputation: 1425

If you are set on using Google Analytics, you could look into using the measurement protocol (covered in this answer) with an http library like requests. It would end up looking like something along these lines

import requests
payload = 'v=1&t=event&tid=UA-XXXXXY&cid=555&ec=video&ea=play&el=holiday&ev=300'
r = requests.post('http://www.google-analytics.com/collect', data=payload)

Upvotes: 5

Related Questions