Created
November 23, 2018 09:52
-
-
Save ozknozsrt/d1b2f7ffdefcb8f689e8e6afd16c6d73 to your computer and use it in GitHub Desktop.
Get UTM
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
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