简体   繁体   中英

GA Measurement protocol 'user' visits

I'm sending some events from Python backend to Google Analytics via requests library using Measurement Protocol. 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. Is there any way to prevent such behavior?

UPD: I am not looking for an option to change User-Agent header. I am looking for an option to exclude GAMP event hits registered as user visits.

You can't omit measurement protocol hits from user calculations because the concept of users is core to GA's reporting architecture.

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. This method will not inflate your user numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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