Skip to content

Instantly share code, notes, and snippets.

@harisenbon
Created May 19, 2016 21:02
Show Gist options
  • Select an option

  • Save harisenbon/4650414822eaf6af03a513a24f5e5b0e to your computer and use it in GitHub Desktop.

Select an option

Save harisenbon/4650414822eaf6af03a513a24f5e5b0e to your computer and use it in GitHub Desktop.
JS: Fill Out UTM Values into an infusionsoft Form
<script>
$(function(){
setFormValue('inf_custom_UTMCampaign', getQueryVal('utm_campaign'));
setFormValue('inf_custom_UTMMedium', getQueryVal('utm_medium'));
setFormValue('inf_custom_UTMSource', getQueryVal('utm_source'));
setFormValue('inf_custom_UTMContent', getQueryVal('utm_content'));
setFormValue('inf_custom_UTMTerm', getQueryVal('utm_term'));
setFormValue('inf_custom_UTMReferurl',document.referrer);
function getQueryVal(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function setFormValue(item, value){
if(value !== undefined || value !== null){
$('[name="' + item + '"]').val( value );
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment