Skip to content

Instantly share code, notes, and snippets.

@ildarkhasanshin
Forked from hunty/parse_utm.js
Created August 5, 2019 09:56
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 ildarkhasanshin/2d329ff8e374780e33bed9ee9f6ac5d2 to your computer and use it in GitHub Desktop.
Save ildarkhasanshin/2d329ff8e374780e33bed9ee9f6ac5d2 to your computer and use it in GitHub Desktop.
Парсит UTM метки и подставляет в скрытые поля
window.onload = function() {
// Parse the URL
function getParameterByName(name) {
var name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var 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.getElementById("property_utm_source").value = source;
document.getElementById("property_utm_medium").value = medium;
document.getElementById("property_utm_campaign").value = campaign;
//U Can use it with Expertsender Forms
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment