Created
May 19, 2016 21:02
-
-
Save harisenbon/4650414822eaf6af03a513a24f5e5b0e to your computer and use it in GitHub Desktop.
JS: Fill Out UTM Values into an infusionsoft Form
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
| <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