So I am using the following code to get my Google Analytics data:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
def initialize_analyticsreporting():
credentials = ServiceAccountCredentials.from_json_keyfile_name(
KEY_FILE_LOCATION, SCOPES)
analytics = build('analyticsreporting', 'v4', credentials=credentials)
return analytics
def get_report(analytics):
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '2019-01-01', 'endDate': '2019-11-25'}],
'metrics': [{'expression':i} for i in METRICS],
'dimensions': [{'name':j} for j in DIMENSIONS],
'pageSize':'100000'
}]
}
).execute()
analytics = initialize_analyticsreporting()
response = get_report(analytics)
However, it doesn't matter what do I specify as my start date and end date. I am always getting the same number of rows which is 2538 in case of session dimension. Moreover, its not even the full dataset. Pulling the very same dimension via Power BI's Google Analytics connector gives me 2845...
I have checked the documentation but it should work for dateRanges property. Maybe there is something about API I am missing?
Thank you in advance for any advice!