Created
October 4, 2013 19:18
-
-
Save devinsays/6831221 to your computer and use it in GitHub Desktop.
Small jQuery plugin to add UTM tracking to links in an element.
This file contains 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.fn.utm_tracking = function(domain, source, medium, campaign) { | |
$(this).find('a[href^="' + domain + '"]').each(function() { | |
var url = $(this).attr('href'); | |
$(this).attr( 'href', url + '?utm_source=' + source + '&utm_medium=' + medium + '&utm_campaign=' + campaign ); | |
}); | |
} | |
// Example Call | |
$(document).ready( function() { | |
$('body').utm_tracking('http://www.example.com','example_source','example_link','example_campaign'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment