Skip to content

Instantly share code, notes, and snippets.

@ozknozsrt
Created November 23, 2018 09:52
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 ozknozsrt/d1b2f7ffdefcb8f689e8e6afd16c6d73 to your computer and use it in GitHub Desktop.
Save ozknozsrt/d1b2f7ffdefcb8f689e8e6afd16c6d73 to your computer and use it in GitHub Desktop.
Get UTM
var getUrl = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search;
$('#getUrl').val(getUrl);
/*-----------------*/
// Parse the URL
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');
// Put the variable names into the hidden fields in the form.
document.getElementsByName("utm_source").value = source;
document.getElementsByName("utm_medium").value = medium;
document.getElementsByName("utm_campaign").value = campaign;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment