Skip to content

Instantly share code, notes, and snippets.

@adesignl
Created December 10, 2013 18:33
Show Gist options
  • Save adesignl/7895626 to your computer and use it in GitHub Desktop.
Save adesignl/7895626 to your computer and use it in GitHub Desktop.
Grab Parameters From Tracking URL And Append Them To A Link On Your Site For Further Use.
function GetURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++){
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam){
return sParameterName[1];
}
}
}
var campaign = GetURLParameter('utm_campaign'),
medium = GetURLParameter('utm_medium'),
source = GetURLParameter('utm_source');
$("a.mentorsignup").each(function() {
var _href = $(this).attr("href");
if (campaign === undefined) {
null;
} else {
$(this).attr("href", _href + '?utm_campaign=' + campaign + '&utm_medium=' + medium + '&utm_source=' + source);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment