尝试使用Measurement Protocol将pageview
点击发送到Google Analytics,Universal属性(使用Python Requests
库发出HTTP请求)
import requests
endpoint = 'https://www.google-analytics.com/collect'
payload = {'v':'1'
,'tid':'UA-XXXXXX-Y'
,'t':'pageview'
,'dl': 'http%3A%2F%2Fvibhorj.com%2Ftest1%2Fpath2'
,'cid':'928534239.3492469166'
}
r = requests.post(url = endpoint, data = payload)
r.status_code返回200(确定),但仍无法看到实时报告或标准报告中的匹配
还尝试了GET请求:
requests.post(url = endpoint, params = payload)
(同样的结果:status_code在200 OK中返回但在GA报告中仍然没有数据)
任何帮助,指针都将受到高度赞赏
[解决!]:
显然我注意到User-Agent
是必须设置的。以下代码为我工作
r = requests.post(url = endpoint, data = dic2
, headers={'User-Agent': 'My User Agent 1.0'})