diff --git a/README.rst b/README.rst index 36d5aec..fa3c3a6 100644 --- a/README.rst +++ b/README.rst @@ -87,6 +87,7 @@ Installation googleanalytics_resource_prefix = /downloads/ googleanalytics.domain = auto googleanalytics.track_events = false + googleanalytics.fields = {} ``resource_prefix`` is an arbitrary identifier so that we can query for downloads in Google Analytics. It can theoretically be any @@ -107,6 +108,8 @@ Installation is always enabled,* ``track_events`` *enables event tracking for other pages as well.* + ``fields`` allows you to specify various options when creating the tracker. See `Google's documentation `. + Setting Up Statistics Retrieval from Google Analytics ----------------------------------------------------- diff --git a/ckanext/googleanalytics/plugin.py b/ckanext/googleanalytics/plugin.py index 5c3d6a1..6339ae1 100644 --- a/ckanext/googleanalytics/plugin.py +++ b/ckanext/googleanalytics/plugin.py @@ -1,3 +1,4 @@ +import ast import logging import urllib import commands @@ -66,6 +67,8 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin): self.googleanalytics_id = config['googleanalytics.id'] self.googleanalytics_domain = config.get( 'googleanalytics.domain', 'auto') + self.googleanalytics_fields = ast.literal_eval(config.get( + 'googleanalytics.fields', '{}')) self.googleanalytics_javascript_url = h.url_for_static( '/scripts/ckanext-googleanalytics.js') @@ -270,6 +273,7 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin): ''' data = {'googleanalytics_id': self.googleanalytics_id, - 'googleanalytics_domain': self.googleanalytics_domain} + 'googleanalytics_domain': self.googleanalytics_domain, + 'googleanalytics_fields': str(self.googleanalytics_fields)} return p.toolkit.render_snippet( 'googleanalytics/snippets/googleanalytics_header.html', data) diff --git a/ckanext/googleanalytics/templates/googleanalytics/snippets/googleanalytics_header.html b/ckanext/googleanalytics/templates/googleanalytics/snippets/googleanalytics_header.html index 1486393..f95fb43 100644 --- a/ckanext/googleanalytics/templates/googleanalytics/snippets/googleanalytics_header.html +++ b/ckanext/googleanalytics/templates/googleanalytics/snippets/googleanalytics_header.html @@ -4,7 +4,7 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - ga('create', '{{googleanalytics_id}}', '{{googleanalytics_domain}}'); + ga('create', '{{googleanalytics_id}}', '{{googleanalytics_domain}}', {{googleanalytics_fields|safe}}); ga('set', 'anonymizeIp', true); ga('send', 'pageview');