简体   繁体   English

GA 衡量协议“用户”访问

[英]GA Measurement protocol 'user' visits

I'm sending some events from Python backend to Google Analytics via requests library using Measurement Protocol.我正在使用测量协议通过requests库将一些事件从 Python 后端发送到 Google Analytics。 The code is straightforward:代码很简单:

GA_ID = settings.GOOGLE_ANALYTICS_PROPERTY_ID

class GoogleAnalytics:

    def __init__(self):
        self._host = 'https://www.google-analytics.com/collect'
        self._v = '1'
        self._tid = GA_ID
        self._cid = str(uuid.uuid4())

    def send_event(self, ec, ea, el):
        payload = {
            'v': self._v,
            'tid': self._tid,
            'cid': self._cid,
            't': 'event',
            'ec': ec,
            'ea': ea,
            'el': el
        }

        r = requests.post(url=self._host, data=payload)

However, when event is sent to GA, it is also reflected as an user visit in Audience with User-agent requests 2.18.4 - this is undesirable since it has nothing to do with actual user.但是,当事件发送到 GA 时,它也会在 Audience with User-agent requests 2.18.4反映为用户访问 - 这是不可取的,因为它与实际用户无关。 Is there any way to prevent such behavior?有什么办法可以防止这种行为吗?

UPD: I am not looking for an option to change User-Agent header. UPD:我不是在寻找更改 User-Agent 标头的选项。 I am looking for an option to exclude GAMP event hits registered as user visits.我正在寻找一个选项来排除注册为用户访问的 GAMP 事件命中。

You can't omit measurement protocol hits from user calculations because the concept of users is core to GA's reporting architecture.您不能从用户计算中省略测量协议命中,因为用户的概念是 GA 报告架构的核心。

A workaround, however, is to mimic all your measurement protocol hits as belonging to a single user.但是,一种解决方法是将所有测量协议命中模拟为属于单个用户。 You can do this by passing a fixed value for your cid or uid parameters.您可以通过为您的ciduid参数传递一个固定值来做到这一点。 This method will not inflate your user numbers.此方法不会夸大您的用户数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM