def fetch_data(_id, analytics, input_date, mode): response = get_report(_id, analytics, mode, input_date, input_date, '0') df = ga_engine.create_df(response) dataframes = [] dataframes.append(df) idx = 0 while (len(df.index) == BATCH_SIZE): idx += BATCH_SIZE response = get_report(_id, analytics, mode, input_date, input_date, str(idx)) df = ga_engine.create_df(response) dataframes.append(df) return pd.concat(dataframes)
def fetch_data_custom(_id, analytics, input_date, end_date, noyears, platform): if noyears == 1: if platform == 'app': response = get_report_app(_id, analytics, 'year', input_date, end_date, '0') else: response = get_report_web(_id, analytics, 'year', input_date, end_date, '0') else: if platform == 'app': response = get_report_app(_id, analytics, '2years', input_date, end_date, '0') else: response = get_report_web(_id, analytics, '2years', input_date, end_date, '0') df = ga_engine.create_df(response) dataframes = [] dataframes.append(df) idx = 0 while (len(df.index) == BATCH_SIZE): idx += BATCH_SIZE if noyears == 1: if platform == 'app': response = get_report_app(_id, analytics, 'year', input_date, end_date, str(idx)) else: response = get_report_web(_id, analytics, 'year', input_date, end_date, str(idx)) else: if platform == 'app': response = get_report_app(_id, analytics, '2years', input_date, end_date, str(idx)) else: response = get_report_web(_id, analytics, '2years', input_date, end_date, str(idx)) df = ga_engine.create_df(response) dataframes.append(df) return pd.concat(dataframes)
def get_report(_id, analytics , start='2017-03-01', end='2017-03-01', page='0'): df = ga_engine.create_df(analytics.reports().batchGet( body = { 'reportRequests': [ { 'viewId': _id, 'dateRanges': [{'startDate': start, 'endDate': end}], 'metrics': [{'expression': 'ga:users'}], 'samplingLevel': 'LARGE', 'pageToken': page, 'pageSize': BATCH_SIZE }] } ).execute()) return df