When submitting an event, using the Google Analytics Measurement Protocol... GA is classifying the events as bot traffic. I can determine this by configuring two views in GA, one with bot filtering on, and one with bot filtering disabled. The events show up consistently in the view with bot filtering disabled.
We do not want to disable the bot filter in our primary view, as this would include a ton of unnecessary bot traffic.
What about this code is tripping up the bot filter?
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()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With