/** * Please make sure to install this in the JavaScript settings of * an Instapage form and _not_ in the HTML settings. */ window.instapageFormSubmitSuccess = function( form ) { /** * * These are the field names in Instapage. Note that hidden fields should * have their "Hidden field name" match exactly. * * The email field will always check for the input type="email" rather than * look for a specific name. If visible fields are added, they will likely require * custom treatment to work properly. */ var fields = [ "email", "utm_source", "utm_medium", "utm_campaign", "utm_content" ]; /******xxxxxx******!¡!¡--[ DO NOT EDIT BELOW THIS LINE ]--¡!¡!******xxxxxx******/ // hold the field => value pairs var values = {}, // the redirect url redirectInput = $( form ).find( 'input[name="redirect"]' ), // create a URL object to pull the hash from redirectUrlObj = new URL( redirectInput.val() ), // since Instapage does not work as expected, build our own query string currentQueryString = new URLSearchParams( window.location.search ); // iterate over the fields and fill values object with name => value pairs $.each( fields, function(key, field){ // grab the email field based on the input type if ( field === 'email' ){ values[field] = $( form ).find( 'input[type="email"]' ).val(); } else { // build the values based on the actual URL presented to the browser values[field] = currentQueryString.get( field ); } }); // set the vale of the redirect input redirectInput.val( redirectUrlObj.origin + redirectUrlObj.pathname + '?' + $.param( values ) + ( Boolean( redirectUrlObj.hash ) ? redirectUrlObj.hash : '' ) ); }