From ffd28f4619e1d605ecf8de517eb6a21f6965c8a7 Mon Sep 17 00:00:00 2001 From: John Glover Date: Wed, 11 Jul 2012 16:40:17 +0100 Subject: [PATCH] Add first batch of Google Analytics track events. --- ckanext/googleanalytics/plugin.py | 4 +- .../public/scripts/ckanext-googleanalytics.js | 53 ++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/ckanext/googleanalytics/plugin.py b/ckanext/googleanalytics/plugin.py index 352dec8..f131877 100644 --- a/ckanext/googleanalytics/plugin.py +++ b/ckanext/googleanalytics/plugin.py @@ -5,7 +5,7 @@ from genshi.filters import Transformer from genshi import HTML from genshi.core import START, TEXT from genshi.filters.transform import INSIDE, EXIT -from pylons import config, request +import pylons import ckan.lib.helpers as h import ckan.plugins as p import gasnippet @@ -67,7 +67,7 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin): stream = stream | Transformer('body/div[@id="scripts"]')\ .append(self.footer_code) - routes = request.environ.get('pylons.routes_dict') + routes = pylons.request.environ.get('pylons.routes_dict') action = routes.get('action') controller = routes.get('controller') diff --git a/ckanext/googleanalytics/public/scripts/ckanext-googleanalytics.js b/ckanext/googleanalytics/public/scripts/ckanext-googleanalytics.js index de1dbaf..bdbdcdc 100644 --- a/ckanext/googleanalytics/public/scripts/ckanext-googleanalytics.js +++ b/ckanext/googleanalytics/public/scripts/ckanext-googleanalytics.js @@ -1,4 +1,55 @@ (function ($) { - $(document).ready(function () { + $(document).ready(function () { + // Google Analytics event tracking + + // alert($(this).attr('href')); + + // 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')]); + }); + + // 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() === "Tags";}) + .next('ul') + .find('a') + .click(function() { + _gaq.push(['_trackEvent', 'Group', 'Click: Tag', $(this).attr('href')]); + }); + + // Visiting /group/history/X + // Compare Button on /group/history/X + // Compare Button on /dataset/history/X + // Tags on right hand sidebar of /dataset/X + // Download button on any /dataset/X/resource[> page + // Data API button on any /dataset/X/resource[> page + }); }(jQuery));