[英]Google Analytics API - ga:day not showing correct data
I am trying to pull Session data by day for particular segments. 我试图按天提取特定细分的会话数据。 I am trying to do this with the script below.
我正在尝试使用下面的脚本来执行此操作。
However, when I use ga:day as a dimension, the sessions returned are much lower than what they are in the Google Analytics user interface. 但是,当我使用ga:day作为维度时,返回的会话比Google Analytics(分析)用户界面中的会话低得多。
Also, the results.get(date) item is returning "None" (if I give a range of dates, it still only comes up with one session number). 另外,results.get(date)项目返回“ None”(如果我给出了一个日期范围,它仍然只带有一个会话号)。
What am I not seeing? 我没看到什么?
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()
值得一看的是,是否需要在Google Analytics(分析)中设置细分-如果您要从细分中提取会话数据,请确保将其设置为会话级别,而不是用户级别,因为当您尝试将其匹配回时,这可能会影响您的数据GA报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.