Created
September 1, 2019 10:58
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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