0
我想拉特定段的白天會話數據。我正在試圖用下面的腳本來做到這一點。谷歌分析API - GA:日不顯示正確的數據
但是,當我使用ga:day作爲維度時,返回的會話數量遠遠低於Google Analytics用戶界面中的會話數量。
此外,results.get(日期)項目返回「無」(如果我給一個日期範圍,它仍然只有一個會話號碼)。
我沒有看到什麼?
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()
我該在哪裏改變? – user1072337
當您在GA中編輯細分時,左下角會出現一個下拉菜單,選擇「用戶」或「會話」級別。 –