简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM