Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to see Measurement protocol hit in GA reports (using Python Request library)

Trying to send pageview hit using Measurement Protocol to Google Analytics, Universal property (using Python's Requests library to make HTTP request)

import requests

endpoint = 'https://www.google-analytics.com/collect'
payload = {'v':'1'
          ,'tid':'UA-XXXXXX-Y'
          ,'t':'pageview'
          ,'dl': 'http%3A%2F%2Fvibhorj.com%2Ftest1%2Fpath2'
          ,'cid':'928534239.3492469166'
    }
r = requests.post(url = endpoint, data = payload)

r.status_code is returned as 200 (OK), but still can't see the hit in Real Time reports or in standard report

also tried GET request:

requests.post(url = endpoint, params = payload)

(same result: status_code returned in 200 OK but still no data in GA reports)

any help, pointers will be highly appreciated

[SOLVED!]: Apparently I notice User-Agent is mandatory to set. Following code worked for me

r = requests.post(url = endpoint, data = dic2
              , headers={'User-Agent': 'My User Agent 1.0'})
like image 890
Vibhor Jain Avatar asked May 31 '17 09:05

Vibhor Jain


1 Answers

To enable to see the Python hits on the tool you have yo uncheck the option of "Exclude all hits from known bots and spiders". Also check the filter if you are not excluding this data in others ways.

enter image description here

Also, it's highly recommended to add the parameter title ("&dt"), this parameter is used on the Report "User Explorer" or in other "reports of behavior section" is not mandatory but you can expect undesired issues with the tool.

Greetings

like image 124
Kemen Paulos Plaza Avatar answered Sep 18 '22 02:09

Kemen Paulos Plaza