paulus
paulus

Reputation: 655

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.

Upvotes: 1

Views: 296

Answers (1)

vinoaj
vinoaj

Reputation: 1674

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.

Upvotes: 1

Related Questions