Created
December 3, 2017 12:19
-
-
Save mabumusa1/fc353b0626568221088bb43e7fb453e8 to your computer and use it in GitHub Desktop.
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
function getParameterByName(name) { | |
var url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
$( "input[name*='mauticform'][type='hidden']" ).each(function(index){ | |
var itemName = $(this).attr('name').match(/\[(.*?)\]/)[1]; | |
var utms = ["gclid", "utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"]; | |
if($.inArray(itemName, utms) !== -1){ | |
var elementName = "input[name='mauticform["+ itemName +"]]"; | |
$(elementName).val(getParameterByName(itemName)) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment