【问题标题】:Google Analytics API - ga:day not showing correct dataGoogle Analytics API - ga:day 没有显示正确的数据
【发布时间】:2017-04-19 21:05:39
【问题描述】:

我正在尝试按天为特定细分提取会话数据。我正在尝试使用下面的脚本来执行此操作。

但是,当我使用 ga:day 作为维度时,返回的会话数远低于 Google Analytics(分析)用户界面中的会话数。

此外,results.get(date) 项返回“无”(如果我给出一个日期范围,它仍然只提供一个会话编号)。

我没看到什么?

def get_segment_sessions(service, profile_id, segment_id):

    return service.data().ga().get(
      ids='ga:' + profile_id,
      segment='gaid::' + segment_id,
      dimensions='ga:day',
      start_date='2017-04-14',
      end_date='2017-04-14',
      metrics='ga:sessions').execute()

def print_results(results):
  # Print data nicely for the user.
  if results:
    print 'View (Profile): %s' % results.get('profileInfo').get('profileName')
    print 'Date: %s' % results.get('date') + ' Total Sessions: %s' % results.get('rows')[0][0]

  else:
    print 'No results found'

def main():
  # Define the auth scopes to request.
  scope = ['https://www.googleapis.com/auth/analytics.readonly']

  # Use the developer console and replace the values with your
  # service account email and relative location of your key file.
  service_account_email = '**********'
  key_file_location = '********'

  # Authenticate and construct service.
  service = get_service('analytics', 'v3', scope, key_file_location,
    service_account_email)
  profile = get_first_profile_id(service)
  print_results(get_results(service, profile))
  get_segments(service)

  #print odd video sessions
  print_results(get_segment_sessions(service, profile, '*********'))

  #print even video sessions
  print_results(get_segment_sessions(service, profile, '********'))


if __name__ == '__main__':
  main()

【问题讨论】:

    标签: python google-analytics


    【解决方案1】:

    如果您在 GA 中设置了细分,值得检查一下 - 如果您想从中提取会话数据,请确保将它们设置为会话级别,而不是用户级别,因为这可能会在您尝试匹配时影响您的数据它返回 GA 报告。

    【讨论】:

    • 我在哪里改变它?
    • 当您在 GA 中编辑细分时,左上角有一个下拉菜单可以选择“用户”或“会话”级别。
    猜你喜欢
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    相关资源
    最近更新 更多