From: Tom Rees Date: Wed, 30 Oct 2013 01:00:28 +0000 Subject: Merge remote-tracking branch 'origin/777-responsive' X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=feb2cc9d9a19e66049d8a546ad654af7ac2921a6 --- Merge remote-tracking branch 'origin/777-responsive' --- --- a/ckanext/ga_report/download_analytics.py +++ b/ckanext/ga_report/download_analytics.py @@ -193,10 +193,6 @@ # Supported query params at # https://developers.google.com/analytics/devguides/reporting/core/v3/reference try: - # Because of issues of invalid responses, we are going to make these requests - # ourselves. - headers = {'authorization': 'Bearer ' + self.token} - args = {} args["sort"] = "-ga:pageviews" args["max-results"] = 100000 @@ -208,16 +204,11 @@ args["filters"] = query args["alt"] = "json" - r = requests.get("https://www.googleapis.com/analytics/v3/data/ga", params=args, headers=headers) - if r.status_code != 200: - raise Exception("Request with params: %s failed" % args) - - results = json.loads(r.content) - print len(results.keys()) - except Exception, e: - log.exception(e) - #return dict(url=[]) - raise e + results = self._get_json(args) + + except Exception, e: + log.exception(e) + return dict(url=[]) packages = [] log.info("There are %d results" % results['totalResults']) @@ -258,37 +249,32 @@ return data def _get_json(self, params, prev_fail=False): - if prev_fail: - import os - ga_token_filepath = os.path.expanduser(config.get('googleanalytics.token.filepath', '')) - if not ga_token_filepath: - print 'ERROR: In the CKAN config you need to specify the filepath of the ' \ - 'Google Analytics token file under key: googleanalytics.token.filepath' - return - - try: - self.token, svc = init_service(ga_token_filepath, None) - except TypeError: - print ('Have you correctly run the getauthtoken task and ' - 'specified the correct token file in the CKAN config under ' - '"googleanalytics.token.filepath"?') - - try: - # Because of issues of invalid responses, we are going to make these requests - # ourselves. + ga_token_filepath = os.path.expanduser(config.get('googleanalytics.token.filepath', '')) + if not ga_token_filepath: + print 'ERROR: In the CKAN config you need to specify the filepath of the ' \ + 'Google Analytics token file under key: googleanalytics.token.filepath' + return + + log.info("Trying to refresh our OAuth token") + try: + from ga_auth import init_service + self.token, svc = init_service(ga_token_filepath, None) + log.info("OAuth token refreshed") + except Exception, auth_exception: + log.error("Oauth refresh failed") + log.exception(auth_exception) + return + + try: headers = {'authorization': 'Bearer ' + self.token} r = requests.get("https://www.googleapis.com/analytics/v3/data/ga", params=params, headers=headers) if r.status_code != 200: - log.info("STATUS: %s" % (r.status_code,)) - log.info("CONTENT: %s" % (r.content,)) - raise Exception("Request with params: %s failed" % params) + log.info("STATUS: %s" % (r.status_code,)) + log.info("CONTENT: %s" % (r.content,)) + raise Exception("Request with params: %s failed" % params) return json.loads(r.content) except Exception, e: - if not prev_fail: - print e - results = self._get_json(self, params, prev_fail=True) - else: log.exception(e) return dict(url=[]) --- a/ckanext/ga_report/templates/ga_report/ga_util.html +++ b/ckanext/ga_report/templates/ga_report/ga_util.html @@ -70,7 +70,6 @@
-

Download

@@ -92,7 +91,7 @@
  • The results are not shown when the number of views/visits is tiny. Where these relate to site pages, results are available in full in the CSV download. Where these relate to users' web browser information, results are not disclosed, for privacy reasons.
  • -
    +
    --- a/ckanext/ga_report/templates/ga_report/publisher/index.html +++ b/ckanext/ga_report/templates/ga_report/publisher/index.html @@ -6,7 +6,6 @@ Usage by Publisher - @@ -25,9 +24,23 @@ - Site Usage ${usage_nav('Publishers')} + + +
  • Site Analytics
  • +
  • Publishers
  • +
    + +
    + +

    + Site-wide + | + Publishers + | + Datasets +

    --- a/ckanext/ga_report/templates/ga_report/publisher/read.html +++ b/ckanext/ga_report/templates/ga_report/publisher/read.html @@ -22,9 +22,24 @@ ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='dataset_csv',id=c.publisher_name or 'all',month=c.month or 'all'))} - Site Usage ${usage_nav('Datasets')} + + +
  • Site Analytics
  • +
  • Datasets
  • +
  • ${c.publisher.title}
  • +
    + +
    +

    + Site-wide + | + Publishers + | + Datasets +

    +

    ${c.publisher.title}

    --- a/ckanext/ga_report/templates/ga_report/site/index.html +++ b/ckanext/ga_report/templates/ga_report/site/index.html @@ -23,9 +23,22 @@ ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv',month=c.month or 'all'))} - Site Usage ${usage_nav('Site-wide')} + + +
  • Site Analytics
  • +
  • Site-wide
  • +
    +
    + +

    + Site-wide + | + Publishers + | + Datasets +

    @@ -168,7 +181,7 @@ CKAN.GA_Reports.bind_sparklines(); CKAN.GA_Reports.bind_sidebar(); CKAN.GA_Reports.bind_month_selector(); - }); + });