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

Viewed 1076

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'})
1 Answers
Related