我无法使用 Python 个请求看到 Google 个分析事件

I cannot see Google Analytics events working, using Python requests

我正在尝试向 https://www.google-analytics.com/collect 发送 post 请求?像这样:

name = user.first_name
    if user.username:
      name += f'[{user.username}]'
    query_params = {
      'v': '1',
      't': 'event',
      'tid': self._config.ga_tracking_id,
      'cid': '555',
      'ec': category,
      'ea': action,
      'el': f'{name}: {label}'
    }
    query = urlencode(query_params)
    requests.post('https://www.google-analytics.com/collect?'+query)

print 输出给我这个:

https://www.google-analytics.com/collect?v=1&t=event&tid=UA-17106xxxx-1&cid=555&ec=category&ea=ACTION&el=Name%5BFullView%5D%3A+nana+with+6+results

我觉得一切正常,但在我的 GA 事件面板上,我没有在实时或行为下看到任何报告

有什么建议吗?

*** 更新 ***

    query_params = {
      'v': '1',
      't': 'event',
      'tid': self._config.ga_tracking_id,
      'cid': '555',
      'ec': category,
      'ea': action,
      'el': f'[{now}]{name}: {label}',
      'dp': '/'
    }
    r = requests.post('https://www.google-analytics.com/collect', data=query_params)

假设这不是一个全新的 Google 分析帐户,并且它至少存在 72 小时,那么它应该正在记录数据。

Post 应该包含 post 正文。

requests.post('https://www.google-analytics.com/collect?'+query)

您正在发送一个 post 请求,但您没有发送 post 正文中的数据。

POST /collect HTTP/1.1
Host: www.google-analytics.com

v=1&t=event&tid=UA-17106xxxx-1&cid=555&ec=category&ea=ACTION&el=Name%5BFullView%5D%3A+nana+with+6+results

post正文

# importing the requests library 
import requests 
  
# api-endpoint 
URL = "https://www.google-analytics.com/collect"

# define user
name = user.first_name
if user.username:
   name += f'[{user.username}]'
  
# defining a params dict for the parameters to be sent to the API 
PARAMS = {
  'v': '1',
  't': 'event',
  'tid': self._config.ga_tracking_id,
  'cid': '555',
  'ec': category,
  'ea': action,
  'el': f'{name}: {label}'
}

# sending POST request and saving the response as response object 
r = requests.post(url = URL, params = PARAMS) 

尝试包含用户代理,例如 'ua'='Opera/9.80'。请参阅此处的文档: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#ecom