Skip to content

Instantly share code, notes, and snippets.

@salvatorecapolupo
Created September 1, 2019 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salvatorecapolupo/4db94b82318aa95b4c0f7c3ed59a3d1f to your computer and use it in GitHub Desktop.
Save salvatorecapolupo/4db94b82318aa95b4c0f7c3ed59a3d1f to your computer and use it in GitHub Desktop.
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