Skip to content

Instantly share code, notes, and snippets.

@chrisking
Created August 26, 2016 15:34
Show Gist options
  • Select an option

  • Save chrisking/df5dc1e4362ddf4601daef4a6c2c7489 to your computer and use it in GitHub Desktop.

Select an option

Save chrisking/df5dc1e4362ddf4601daef4a6c2c7489 to your computer and use it in GitHub Desktop.
GA of AC info
Meteor.startup(function($) {
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|mp4)$/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(['_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(/^mailto\:/i)) {
jQuery(this).click(function() {
var mailLink = href.replace(/^mailto\:/i, '');
_gaq.push(['_trackEvent', 'Email', 'Click', mailLink]);
});
}
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;
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment