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?
我正在开发一个具有REST API的网站,并且我想使用Google Analytics事件跟踪API使用情况。是否有一种简单的方法可以从Python触发GA事件,而不涉及仅仅为了发送javascript请求而加载整个webbrowser组件?
6 个解决方案
#1
11
There is an open source implementation of Google-Analytics for Mobile in python available here: http://github.com/b1tr0t/Google-Analytics-for-Mobile--python-
这里有一个用于python的Google-Analytics for Mobile的开源实现: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.
您可以通过导入“track_page_view”并为其提供适当的WSGI请求环境,将其集成到您自己的设置中。
#2
12
This project called PyGA is much better. Unlike "Google-Analytics for Mobile" project on github it is well documentated and has rich API.
这个名为PyGA的项目要好得多。与github上的“Google-Analytics for Mobile”项目不同,它具有良好的文档记录并且具有丰富的API。
#3
6
There's a question for this in SO, Generate Google Analytics events (__utm.gif requests) serverside.
在SO,生成Google Analytics事件(__ utm.gif请求)服务器端有一个问题。
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).
在谷歌搜索“服务器端谷歌分析”时,你会发现SO问题中提供的相同来源与更相关的来源相同。虽然在名为Server Side Google Analytics的PHP中有一个lib可以执行此操作。最后一次提交是从2009年4月28日开始的,所以我不知道它是否正常工作或者是否可以跟踪事件(而且它是在php中,而不是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).
我知道有一个官方的谷歌分析跟踪解决方案没有javascript(也检查他们博客的发布说明)的移动应用程序,它甚至附带一个PHP库。也许你可以“欺骗”他们的服务并且表现得像你的应用程序是一个移动的应用程序来跟踪你的事件,用Python重写这个lib? (我不知道这是否违反谷歌的TOS,你应该阅读以防万一)。
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.
恕我直言,如果谷歌分析真的是你想要做你想要的唯一方式,一切都失败了,我会尝试使用webbrowser组件。
As a last resource, you can try to create a simple analytics tool to track your api usage using google's documentation.
作为最后一个资源,您可以尝试使用Google的文档创建一个简单的分析工具来跟踪您的API使用情况。
(If you think none of these suggestions are useful, I would try to search "google analytics without javascript" on google. Good luck!)
(如果你认为这些建议都没有用,我会尝试在google上搜索“google analytics without javascript”。祝你好运!)
#4
1
In the present you can use Google Analytics Measurement Protocol. There are some python libraries to send events, for example xoxzo.galib:
目前,您可以使用Google Analytics测量协议。有一些python库可以发送事件,例如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.
或google-measurement-protocol,或者您可以使用本指南的python请求自行编写请求。
#5
0
Basically it boils down to: https://gist.github.com/canburak/1593381
基本上它归结为:https://gist.github.com/canburak/1593381
For more information about the parameters etc: https://medium.com/python-programming-language/80eb9691d61f
有关参数等的更多信息,请访问:https://medium.com/python-programming-language/80eb9691d61f
#6
0
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):
所有其他答案都是针对过时的ga.js协议,这个库似乎实现了更新的universal.js(我还没试过):
https://github.com/analytics-pros/universal-analytics-python
#1
11
There is an open source implementation of Google-Analytics for Mobile in python available here: http://github.com/b1tr0t/Google-Analytics-for-Mobile--python-
这里有一个用于python的Google-Analytics for Mobile的开源实现: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.
您可以通过导入“track_page_view”并为其提供适当的WSGI请求环境,将其集成到您自己的设置中。
#2
12
This project called PyGA is much better. Unlike "Google-Analytics for Mobile" project on github it is well documentated and has rich API.
这个名为PyGA的项目要好得多。与github上的“Google-Analytics for Mobile”项目不同,它具有良好的文档记录并且具有丰富的API。
#3
6
There's a question for this in SO, Generate Google Analytics events (__utm.gif requests) serverside.
在SO,生成Google Analytics事件(__ utm.gif请求)服务器端有一个问题。
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).
在谷歌搜索“服务器端谷歌分析”时,你会发现SO问题中提供的相同来源与更相关的来源相同。虽然在名为Server Side Google Analytics的PHP中有一个lib可以执行此操作。最后一次提交是从2009年4月28日开始的,所以我不知道它是否正常工作或者是否可以跟踪事件(而且它是在php中,而不是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).
我知道有一个官方的谷歌分析跟踪解决方案没有javascript(也检查他们博客的发布说明)的移动应用程序,它甚至附带一个PHP库。也许你可以“欺骗”他们的服务并且表现得像你的应用程序是一个移动的应用程序来跟踪你的事件,用Python重写这个lib? (我不知道这是否违反谷歌的TOS,你应该阅读以防万一)。
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.
恕我直言,如果谷歌分析真的是你想要做你想要的唯一方式,一切都失败了,我会尝试使用webbrowser组件。
As a last resource, you can try to create a simple analytics tool to track your api usage using google's documentation.
作为最后一个资源,您可以尝试使用Google的文档创建一个简单的分析工具来跟踪您的API使用情况。
(If you think none of these suggestions are useful, I would try to search "google analytics without javascript" on google. Good luck!)
(如果你认为这些建议都没有用,我会尝试在google上搜索“google analytics without javascript”。祝你好运!)
#4
1
In the present you can use Google Analytics Measurement Protocol. There are some python libraries to send events, for example xoxzo.galib:
目前,您可以使用Google Analytics测量协议。有一些python库可以发送事件,例如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.
或google-measurement-protocol,或者您可以使用本指南的python请求自行编写请求。
#5
0
Basically it boils down to: https://gist.github.com/canburak/1593381
基本上它归结为:https://gist.github.com/canburak/1593381
For more information about the parameters etc: https://medium.com/python-programming-language/80eb9691d61f
有关参数等的更多信息,请访问:https://medium.com/python-programming-language/80eb9691d61f
#6
0
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):
所有其他答案都是针对过时的ga.js协议,这个库似乎实现了更新的universal.js(我还没试过):
https://github.com/analytics-pros/universal-analytics-python