Skip to main content

What If I can't change the field name

We normally reocmmend you to match our naming convention when you include your hidden fields in your form. How can I track UTMs in my optin form?

But we know sometimes this is not feasible. You can't just change the name, id or class of the fields. So, if you want to use different naming convention. You can use the following code:

<script>
handl_custom_params=[];
var handl_js=document.createElement("script");
handl_js.setAttribute("src","https://track.utmsimple.com/utm.js?license=<licensekey>"),
document.head.appendChild(handl_js),
handl_js.onload=function(){
	setTimeout(function(){
		all_params = HandL.getAll()
		mapping = {
			utm_source: ["Question133","Question134"],
			utm_medium: ["Question135","Question136"],
		}
        Object.keys(all_params).map(function(x,y){
        	field_names = mapping[x]
        	if (!Array.isArray(field_names)){
        		field_names = [field_names]
        	}
        	
        	field_names.forEach(function(field_name,y2){
				if (jQuery('#'+field_name).length > 0){
					jQuery('#'+field_name).val(all_params[x]).attr('value',all_params[x]).parent().parent().hide()	
				}	
        	})
        	
        })
	}, 500);
};
</script>

See the mapping field, this is where you map your new field name. In the example above, the id Question133 and Question134 will be filled by utm_source and Question135 and Question136 will be autofilled by utm_medium.

If you have a different requirement or need help, please have a chat with us.