From f254d1afd7aef8d89355522fd16070b7980c31d8 Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 23 Oct 2012 10:21:41 +0100 Subject: [PATCH] Tweaks to google analytics CKAN 2.0 JS module 1. Specified `resource_prefix` and `resource_url` context more tightly (could be global context) 2. Changed `this.href` to `jQuery(this).prop('href')` as it will never throw a syntax error when upon the condition of a `a.resource-url-analytics` not having a `href` attribute 3. Also added check so that if no `href` is present it doesn't send a blank link to google analytics --- .../googleanalytics_event_tracking.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js b/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js index a6c9f35..322463c 100644 --- a/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js +++ b/ckanext/googleanalytics/fanstatic_library/googleanalytics_event_tracking.js @@ -5,10 +5,12 @@ this.ckan.module('google-analytics', function(jQuery, _) { googleanalytics_resource_prefix: '' }, initialize: function() { - resource_prefix = this.options.googleanalytics_resource_prefix; - jQuery('a.resource-url-analytics').on('click', function(){ - resource_url = resource_prefix + encodeURIComponent(this.href); - _gaq.push(['_trackPageview', resource_url]); + jQuery('a.resource-url-analytics').on('click', function() { + var resource_prefix = this.options.googleanalytics_resource_prefix; + var resource_url = resource_prefix + encodeURIComponent(jQuery(this).prop('href')); + if (resource_url) { + _gaq.push(['_trackPageview', resource_url]); + } }); } }