提交事件时,使用 Google Analytics Measurement Protocol ... GA 将事件归类为机器人流量。我可以通过在 GA 中配置两个 View 来确定这一点,一个启用机器人过滤,一个禁用机器人过滤。在禁用机器人过滤的情况下,事件始终显示在 View 中。
我们不想在我们的主要 View 中禁用机器人过滤器,因为这会包含大量不必要的机器人流量。
这段代码是怎么触发机器人过滤器的?
payload = {
'v': 1,
't': 'event',
'tid': tracking_id,
'ec': category,
'ea': action,
'el': label
}
if value and type(value) is int:
payload['ev'] = value
if user_id:
payload['uid'] = user_id
else:
payload['cid'] = str(uuid4())
requests.post(
'https://www.google-analytics.com/collect',
data=payload,
headers=requests.utils.default_headers()
)
最佳答案
requests.utils.default_headers()
为您提供“python-requests”的默认用户代理(根据 the code for default_headers()
和 default_user_agent()
).
宣布你是一个 Python 程序——大概从同一个 IP 重复调用他们的服务器——听起来像是机器人的定义! :)
在您的用户代理上撒谎可能会更幸运——例如,通过从您的(真实)网络浏览器中获取用户代理字符串。
关于python - Google Analytics、服务器端跟踪和机器人过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53396644/