Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple way to add utm_medium / utm_source to any inner link inside your website, as described well here: https://support.google.com/analytics/answer/1033867?hl=en
jQuery(document).ready(function( $ ){
//track single link
var original_link1 = jQuery("a#single").attr('href');
jQuery(elem).attr('href', original_link + '?utm_source=A&utm_medium=B&utm_campaign=C');
//track multi-links
var link_group_identifier = 'a.group';
jQuery( link_group_identifier ).each(function(i, elem) {
var original_link = jQuery(elem).attr('href');
jQuery(elem).attr('href', original_link + '?utm_source=A&utm_medium=B&utm_campaign=C');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.