Skip to content

Commit

Permalink
still the same stuff of loading ga python class #12
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpe committed Dec 12, 2018
1 parent 4b04e8b commit 1b89685
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions userMng/third_party_services/google_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class Google_Analytics:
https://developers.google.com/analytics/devguides/reporting/core/dimsmets
https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py
"""
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'client_secrets.json'
VIEW_ID = '181239651'


def initialize_analyticsreporting(self):
"""
Expand All @@ -18,8 +16,9 @@ def initialize_analyticsreporting(self):
Returns:
An authorized Analytics Reporting API V4 service object.
"""

credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION, SCOPES)
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'client_secrets.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(self.KEY_FILE_LOCATION, self.SCOPES)

# Build the service object.
analytics = build('analyticsreporting', 'v4', credentials=credentials)
Expand All @@ -37,11 +36,12 @@ def get_report(self, analytics):
The Analytics Reporting API V4 response.
"""
VIEW_ID = '181239651'
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'viewId': self.VIEW_ID,
'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
'metrics': [{'expression': 'ga:sessions', "expression":"ga:pageviews"}],
'dimensions': [{'name': 'ga:country', "name":"ga:browser"}]
Expand Down

0 comments on commit 1b89685

Please sign in to comment.