From d26c8b8d8bae814ba1fc05369aeb0add5265ebb3 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 1 Mar 2013 14:36:40 +0100 Subject: [PATCH 1/2] analytics for downloads and other non-html-links --- _includes/headerbottom.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/_includes/headerbottom.html b/_includes/headerbottom.html index 52a046fcf..34664f6f0 100644 --- a/_includes/headerbottom.html +++ b/_includes/headerbottom.html @@ -11,7 +11,18 @@ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); - + var f = function(event){ + _gaq.push(['_trackEvent','Downloads','Download',$(this).attr('href')]); + }; + function endsWith(str, suffix) { + return str.indexOf(suffix, str.length - suffix.length) !== -1; + } + $(function(){ + $('a').filter(function(){ + var href = $(this).attr('href'); + return !endsWith(href,'/') && !endsWith(href,'html'); + }).on('click',f); + }); \ No newline at end of file From 169561b867bebbf040cfae9cd306b86491de1ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 16 Apr 2013 13:32:06 +0200 Subject: [PATCH 2/2] Handle analytics for downloads without target blank. Use a timeout of 200ms to let GA do its job. --- _includes/headerbottom.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_includes/headerbottom.html b/_includes/headerbottom.html index f7ca06305..211324761 100644 --- a/_includes/headerbottom.html +++ b/_includes/headerbottom.html @@ -32,7 +32,13 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); var f = function(event){ - _gaq.push(['_trackEvent','Downloads','Download',$(this).attr('href')]); + var href = $(this).attr('href'); + var target = $(this).attr('target'); + _gaq.push(['_trackEvent','Downloads','Download',href]); + if (target === undefined || target.toLowerCase() != '_blank') { + setTimeout(function() { location.href = href; }, 200); + return false; + } }; function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1;