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'})
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.
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
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