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

1

7

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'})
Schoolboy answered 31/5, 2017 at 9:21 Comment(0)
L
7

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

Linkwork answered 31/5, 2017 at 10:31 Comment(3)
Thanks for your responseSchoolboy
Is this removed? I don't see the checkbox named Bot Filtering in the interfaceEver
Is still there, on the "View Configuration". Make sure that you got the edit privilegesLinkwork

© 2022 - 2024 — McMap. All rights reserved.