从python跟踪到Google分析

2024-04-23 12:00:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从python后端跟踪GA事件,以便进行电子商务分析。它的写法是in the official documentation,即发送一个post请求,没有显示任何内容,我在仪表板中仍然没有访问者,但是google用200和GIF回复。在

在这个例子中,我发送了一个pageview,显然从后端做没有意义,但是它对于调试来说足够简单了。在

这是我的代码:

import requests

payload = {
    'v': 1,
    'tid': 'UA-XXXXXX-Y',
    'cid': 555,
    't': 'pageview',
    'dp': '/home',
}
print 'sending to GA...'
r = requests.post("http://www.google-analytics.com/collect", data=payload)
if r.ok:
    print 'ok'
else:
    print ':('

我已经禁用了GA中的所有过滤器


Tags: thein内容documentationgoogle事件okpost