我试图每天为特定段的段落拉动会话数据。我正在尝试使用下面的脚本来完成此操作。
但是,当我使用GA:DAY作为维度时,返回的会话远低于Google Analytics(分析(用户界面中的会话。
另外,结果。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()
值得检查的一件事是否在GA中的片段设置 - 如果您想从它们中获取会话数据,请确保将它们设置为会话级别,而不是用户级别,因为这可能是当您尝试将其匹配到GA报告时,会影响您的数据。