Browse files

Adding

  • Loading branch information...
1 parent ae47384 commit aa0d96f390a37c21b4aa36cc31946f5658096109 @kirkhess committed Feb 8, 2012
Showing with 35 additions and 0 deletions.
  1. +35 −0 gaevents.js
View
35 gaevents.js
@@ -0,0 +1,35 @@
+<script type="text/javascript">
+if (typeof jQuery != 'undefined') {
+ jQuery(document).ready(function($) {
+ var filetypes = /\.(pdf|txt|dijv|xml)$/i;
+ var baseHref = '';
+ if (jQuery('base').attr('href') != undefined)
+ baseHref = jQuery('base').attr('href');
+ jQuery('a').each(function() {
+ var href = jQuery(this).attr('href');
+ if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
+ jQuery(this).click(function() {
+ var extLink = href.replace(/^https?\:\/\//i, '');
+ _gaq.push(['_link', href]);
+ _gaq.push(['_trackEvent', 'External', 'Click', extLink]);
+ if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
+ setTimeout(function() { location.href = href; }, 200);
+ return false;
+ }
+ });
+ }
+ else if (href && href.match(filetypes)) {
+ jQuery(this).click(function() {
+ var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
+ var filePath = href;
+ _gaq.push(['_trackEvent', 'Download', 'Click-' + extension, filePath]);
+ if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
+ setTimeout(function() { location.href = baseHref + href; }, 200);
+ return false;
+ }
+ });
+ }
+ });
+ });
+}
+</script>

0 comments on commit aa0d96f

Please sign in to comment.