diff --git a/README.rst b/README.rst
index 4896519..6f97c99 100644
--- a/README.rst
+++ b/README.rst
@@ -26,28 +26,6 @@ Features
``ckanext.googleanalytics.plugin._post_analytics``
-* Adds Google Analytics Event Tracking to group links on the home page,
- user profile links, editing and saving user profiles, etc.
-
- *Only if* ``googleanalytics.track_events = true`` *is in your CKAN ini file.*
-
- *CKAN 1.x only*.
-
-* Puts download stats into dataset pages, e.g. "[downloaded 4 times]".
-
- *CKAN 1.x only.*
-
-* Provides a ``/analytics/dataset/top`` page that shows the most popular
- datasets and resources
-
- *CKAN 1.x only*
-
-CKAN 1.x Support
-----------------
-
-To use ckanext-googleanalytics with CKAN 1.x, make sure you have
-``ckan.legacy_templates = true`` in your CKAN ini file.
-
Installation
------------
@@ -81,13 +59,7 @@ Installation
(If there are other plugins activated, add this to the list. Each
plugin should be separated with a space).
-4. If you are using this plugin with a version of CKAN < 2.0 then you should
- also put the following in your ini file::
-
- ckan.legacy_templates = true
-
-
-5. Finally, there are some optional configuration settings (shown here
+4. Finally, there are some optional configuration settings (shown here
with their default settings)::
googleanalytics_resource_prefix = /downloads/
diff --git a/ckanext/googleanalytics/assets/googleanalytics_event_tracking.js b/ckanext/googleanalytics/assets/googleanalytics_event_tracking.js
new file mode 100644
index 0000000..6b67fd2
--- /dev/null
+++ b/ckanext/googleanalytics/assets/googleanalytics_event_tracking.js
@@ -0,0 +1,17 @@
+// Add Google Analytics Event Tracking to resource download links.
+this.ckan.module("google-analytics", function(jQuery, _) {
+ "use strict";
+ return {
+ options: {
+ googleanalytics_resource_prefix: ""
+ },
+ initialize: function() {
+ jQuery("a.resource-url-analytics").on("click", function() {
+ var resource_url = encodeURIComponent(jQuery(this).prop("href"));
+ if (resource_url) {
+ ga("send", "event", "Resource", "Download", resource_url);
+ }
+ });
+ }
+ };
+});
diff --git a/ckanext/googleanalytics/assets/webassets.yml b/ckanext/googleanalytics/assets/webassets.yml
new file mode 100644
index 0000000..a439628
--- /dev/null
+++ b/ckanext/googleanalytics/assets/webassets.yml
@@ -0,0 +1,5 @@
+event_tracking:
+ filters: rjsmin
+ output: ckanext-googleanalytics/event_tracking.js
+ contents:
+ - googleanalytics_event_tracking.js
diff --git a/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js b/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js
deleted file mode 100644
index 60bcb5c..0000000
--- a/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js
+++ /dev/null
@@ -1,16 +0,0 @@
-// Add Google Analytics Event Tracking to resource download links.
-this.ckan.module('google-analytics', function(jQuery, _) {
- return {
- options: {
- googleanalytics_resource_prefix: ''
- },
- initialize: function() {
- jQuery('a.resource-url-analytics').on('click', function() {
- var resource_url = encodeURIComponent(jQuery(this).prop('href'));
- if (resource_url) {
- ga('send', 'event', 'Resource', 'Download', resource_url);
- }
- });
- }
- }
-});
diff --git a/ckanext/googleanalytics/ga_auth.py b/ckanext/googleanalytics/ga_auth.py
index a958b1a..44bdc8f 100644
--- a/ckanext/googleanalytics/ga_auth.py
+++ b/ckanext/googleanalytics/ga_auth.py
@@ -2,7 +2,15 @@ import httplib2
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
-from pylons import config
+from ckan.exceptions import CkanVersionException
+import ckan.plugins.toolkit as tk
+
+try:
+ tk.requires_ckan_version("2.9")
+except CkanVersionException:
+ from pylons import config
+else:
+ config = tk.config
def _prepare_credentials(credentials_filename):
@@ -43,7 +51,6 @@ def get_profile_id(service):
if not accounts.get("items"):
return None
-
accountName = config.get("googleanalytics.account")
webPropertyId = config.get("googleanalytics.id")
for acc in accounts.get("items"):
diff --git a/ckanext/googleanalytics/legacy_public/scripts/ckanext-googleanalytics.js b/ckanext/googleanalytics/legacy_public/scripts/ckanext-googleanalytics.js
deleted file mode 100644
index 8e9047d..0000000
--- a/ckanext/googleanalytics/legacy_public/scripts/ckanext-googleanalytics.js
+++ /dev/null
@@ -1,72 +0,0 @@
-(function ($) {
- $(document).ready(function () {
- // Google Analytics event tracking
-
- // group links on home page
- $('body.home div.group a').click(function() {
- _gaq.push(['_trackEvent', 'Home', 'Click: Group Link', $(this).attr('href')]);
- });
-
- // clicking on user name (go to profile)
- $('div.account span.ckan-logged-in a').first().click(function() {
- _gaq.push(['_trackEvent', 'User', 'Click: User Name', $(this).attr('href')]);
- });
-
- // In user profile, clicking on Edit Profile
- $('body.user div#minornavigation a')
- .filter(function(index) {return $(this).text() === "Edit Profile";})
- .click(function() {
- _gaq.push(['_trackEvent', 'User', 'Click: Tab', 'Edit Profile']);
- });
-
- // Clicking Save Changes on Edit Profile page
- $('body.user.edit input#save').click(function() {
- _gaq.push(['_trackEvent', 'User', 'Click: Button', 'Save Profile Changes']);
- });
-
- // Clicking on any dataset link on User Profile page
- $('body.user.read ul.datasets a').click(function() {
- _gaq.push(['_trackEvent', 'User', 'Click: Dataset Link', $(this).attr('href')]);
- });
-
- // Compare Button on /dataset/history/X
- $('body.package.history form#dataset-revisions input[name="diff"]').click(function() {
- _gaq.push(['_trackEvent', 'Dataset', 'Click: Button', 'Compare History']);
- });
-
- // Tags on right hand sidebar of /dataset/X
- $('body.package.read div#sidebar h3')
- .filter(function(index) {return $(this).text().indexOf("Tags") != -1;})
- .next('ul')
- .find('a')
- .click(function() {
- _gaq.push(['_trackEvent', 'Dataset', 'Click: Tag', $(this).attr('href')]);
- });
-
- // Any of the group links on /group
- $('body.group.index table.groups a').click(function() {
- _gaq.push(['_trackEvent', 'Group', 'Click: Group Link', $(this).attr('href')]);
- });
-
- // Clicking any of the right hand sidebar tags on /group/X
- $('body.group.read div#sidebar h2')
- .filter(function(index) {return $(this).text().indexOf("Tags") != -1;})
- .next('ul')
- .find('a')
- .click(function() {
- _gaq.push(['_trackEvent', 'Group', 'Click: Tag', $(this).attr('href')]);
- });
-
- // Visiting /group/history/X
- $('body.group div#minornavigation ul.nav a')
- .filter(function(index) {return $(this).text().indexOf("History") != -1;})
- .click(function() {
- _gaq.push(['_trackEvent', 'Group', 'Click: History Tab', $(this).attr('href')]);
- });
-
- // Compare Button on /group/history/X
- $('body.group.history form#group-revisions input[name="diff"]').click(function() {
- _gaq.push(['_trackEvent', 'Group', 'Click: Button', 'Compare History']);
- });
- });
-}(jQuery));
diff --git a/ckanext/googleanalytics/legacy_templates/summary.html b/ckanext/googleanalytics/legacy_templates/summary.html
deleted file mode 100644
index 3be593c..0000000
--- a/ckanext/googleanalytics/legacy_templates/summary.html
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
Note: this data does not include API calls
- -Dataset | -Unique views (last 14 days) | -Unique views (since recording started) | -
---|---|---|
${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))} - | -${recent} | -${ever} | -
Resource | -Downloads (last 14 days) | -Downloads (since recording started) | -
---|---|---|
${h.link_to(h.truncate(resource.description, length=50,whole_word=True) if resource.description else resource.format, h.url_for(controller='package',action='resource_read',id=resource.resource_group.package.id,resource_id=resource.id))} - in ${h.link_to(resource.resource_group.package.title or resource.resource_group.package.name, h.url_for(controller='package', action='read', id=resource.resource_group.package.name))} - |
- ${recent} | -${ever} | -