Skip to content

Instantly share code, notes, and snippets.

@schmolzp
Created February 14, 2017 19:15
Show Gist options
  • Select an option

  • Save schmolzp/254ad51db653117ec0c2e6eda8b61113 to your computer and use it in GitHub Desktop.

Select an option

Save schmolzp/254ad51db653117ec0c2e6eda8b61113 to your computer and use it in GitHub Desktop.
MailChimp Form Parse
// Parse parameters in URL
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
var checkNull = results == null ? '' : results[1] || 0;
return checkNull;
}
// Create hidden input elems and add them to form
function addFormElem(paramName, fieldName) {
var paramValue = $.urlParam(paramName);
// This has already been XML escaped for OmniUpdate
var $utmEl = $("<input type='hidden' name='" + fieldName + "' value='" + paramValue + "' />");
if (paramValue != "") {
$("#mc-embedded-subscribe-form").prepend($utmEl);
}
}
// Name of the field tag as you added in your email marketing provider
var utmParams = {
"utm_source" : "USOURCE",
"utm_medium" : "UMEDIUM",
"utm_campaign" : "UCAMPAIGN",
"utm_content" : "UCONTENT"
};
// Loop through object and add input elem for respective key/value
for (var param in utmParams) {
addFormElem(param, utmParams[param]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment