How to trigger Google Analytics events from Python?

谁都会走 提交于 2019-11-28 22:56:06

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.

This project called PyGA is much better. Unlike "Google-Analytics for Mobile" project on github it is well documentated and has rich API.

GmonC

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!)

In the present you can use Google Analytics Measurement Protocol. There are some python libraries to send events, for example xoxzo.galib:

client = HitClient('UA-12345678-1')
client.send_hit('event', event_category='auth', event_action='signup')

Or google-measurement-protocol or you can write requests yourself with python-requests by this guide.

All other answers are for the outdated ga.js protocol, this library seems to implement the newer universal.js (I didn't try it yet):

https://github.com/analytics-pros/universal-analytics-python

Basically it boils down to: https://gist.github.com/canburak/1593381

For more information about the parameters etc: https://medium.com/python-programming-language/80eb9691d61f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!