Tracking to Google Analytics from python

2019-05-23 06:50发布

问题:

I'm trying to track GA events from python backend for ecommerce analysis. The way it's written in the official documentation, that is sending a post request, nothing shows up, I still have zero visitors in the dashboard, but google replies with 200 and a GIF.

In this example I'm sending a pageview, which obviously makes no sense doing from the backend, but it's simple enough for debugging.

This is my code:

import requests

payload = {
    'v': 1,
    'tid': 'UA-XXXXXX-Y',
    'cid': 555,
    't': 'pageview',
    'dp': '/home',
}
print 'sending to GA...'
r = requests.post("http://www.google-analytics.com/collect", data=payload)
if r.ok:
    print 'ok'
else:
    print ':('

I have disabled all filters in GA.

回答1:

I think it is an authentication problem try using postman and try your post url works or not



回答2:

It seems that it was filters anyway, mysteriously started working properly :(