Created
February 14, 2017 19:15
-
-
Save schmolzp/254ad51db653117ec0c2e6eda8b61113 to your computer and use it in GitHub Desktop.
MailChimp Form Parse
This file contains hidden or 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
| // 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