python - Google Analytics、服务器端跟踪和机器人过滤器

标签 python google-analytics

提交事件时,使用 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/

相关文章:

python - azure 批处理网络配置 -> "failed to authenticate"

python - 有什么好方法对时间序列股票数据进行分组吗?

ios - iOS 版 Google Analytics 中的线程崩溃

angularjs - 为Google Analytics(分析)中的报告设置默认路径

ASP.Net codebehind - 获取谷歌付费广告信息

python - 酸洗错误: Can't pickle <type 'function' > with python process pool executor

python - 使用 Scapy 提取 TCP 数据

python - 如何在pycharm中解析 'from bitly_api import Connection, BitlyError, Error'?

c# - C# 中的 Google Analytics API - 请求执行失败 : https://www. google.com/analytics/feeds/accounts/default

javascript - 我如何通过 angulartics2 跟踪 `ecommerce:addItem` 或 `ecommerce:addTransaction`?