Merge pull request #19 from aptivate/fields-config
Allow fields to be specified when creating the tracker
This commit is contained in:
commit
148d52fe9f
|
@ -87,6 +87,7 @@ Installation
|
||||||
googleanalytics_resource_prefix = /downloads/
|
googleanalytics_resource_prefix = /downloads/
|
||||||
googleanalytics.domain = auto
|
googleanalytics.domain = auto
|
||||||
googleanalytics.track_events = false
|
googleanalytics.track_events = false
|
||||||
|
googleanalytics.fields = {}
|
||||||
|
|
||||||
``resource_prefix`` is an arbitrary identifier so that we can query
|
``resource_prefix`` is an arbitrary identifier so that we can query
|
||||||
for downloads in Google Analytics. It can theoretically be any
|
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
|
is always enabled,* ``track_events`` *enables event tracking for other
|
||||||
pages as well.*
|
pages as well.*
|
||||||
|
|
||||||
|
``fields`` allows you to specify various options when creating the tracker. See `Google's documentation <https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference>`.
|
||||||
|
|
||||||
Setting Up Statistics Retrieval from Google Analytics
|
Setting Up Statistics Retrieval from Google Analytics
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ast
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
import urllib
|
||||||
import commands
|
import commands
|
||||||
|
@ -66,6 +67,8 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
||||||
self.googleanalytics_id = config['googleanalytics.id']
|
self.googleanalytics_id = config['googleanalytics.id']
|
||||||
self.googleanalytics_domain = config.get(
|
self.googleanalytics_domain = config.get(
|
||||||
'googleanalytics.domain', 'auto')
|
'googleanalytics.domain', 'auto')
|
||||||
|
self.googleanalytics_fields = ast.literal_eval(config.get(
|
||||||
|
'googleanalytics.fields', '{}'))
|
||||||
self.googleanalytics_javascript_url = h.url_for_static(
|
self.googleanalytics_javascript_url = h.url_for_static(
|
||||||
'/scripts/ckanext-googleanalytics.js')
|
'/scripts/ckanext-googleanalytics.js')
|
||||||
|
|
||||||
|
@ -270,6 +273,7 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
data = {'googleanalytics_id': self.googleanalytics_id,
|
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(
|
return p.toolkit.render_snippet(
|
||||||
'googleanalytics/snippets/googleanalytics_header.html', data)
|
'googleanalytics/snippets/googleanalytics_header.html', data)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
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');
|
})(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('set', 'anonymizeIp', true);
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue