…and everything went awesome with the testing and integration!, the only thing is that when i have more than 1 form inside the same page then this script doesn’t work, the script only works for 1 form.
Is there a pending adjust i need to add to the script so i can make it work even if i got more than 1 form per page?.
For the simple case (Without cockle) - use this code:
<script>
var queryString = window.location.search;
console.log(queryString);
// ?utm_source=facebook&utm_medium=post&utm_campaign=webflow
var URLSearchParams_wb = new URLSearchParams(queryString);
const utmParameters = [
"utm_source",
"utm_medium",
"utm_campaign"
];
for (const utm_element of utmParameters) {
/* if utm_source exist */
$( "form" ).each(function( index ) {
if(URLSearchParams_wb.has(utm_element)){
console.log(utm_element + "is exist");
/* get UTM value of this utm param */
var value = URLSearchParams_wb.get(utm_element)
/* change form hidden feild to this utm url value */
$( this ).find("."+utm_element).val(value);
}
})
}/* end for loop */
</script>
**by Cockle the code already works with more than one form.
I already have the cookie into the project but it only applys to one form, any guess why is that and what i’m doing wrong? thanks a lot for your help!!