1
嘗試(使用Python的Requests
庫使HTTP請求)無法看到測量協議砸在GA報告(使用Python請求庫)
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若要發送使用測量協議pageview
命中谷歌Analytics(分析),通用屬性.status_code返回爲200(OK),但仍然無法實時看到命中報告或標準報告
還試圖GET請求:
requests.post(url = endpoint, params = payload)
(相同的結果:STATUS_CODE在返回200 OK,但仍然在GA沒有數據報告)
任何幫助,指針將不勝感激
[解決!]: 顯然我注意到User-Agent
是強制性的組。下面的代碼爲我工作
r = requests.post(url = endpoint, data = dic2
, headers={'User-Agent': 'My User Agent 1.0'})
感謝您的回覆 –