calin-beard
11/13/2017 - 4:34 PM

use URL UTM parameters in fields - without dynamic text replacement

use URL UTM parameters in fields - without dynamic text replacement

<script>
ijQuery(document).ready(function(){  
// function that gets the url parameters  
  var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
	};
  
  
   var utmSourcesFieldName = 'utm_source'; // the name of the field is the same as the url parameter
   ijQuery("input[name='" + base64_encode(utmSourcesFieldName) + "']").attr('value', getUrlParameter(utmSourcesFieldName));
});
</script>