localStorage
to persist tracking data across pages.To track a form's source in Webflow, you can use hidden fields that capture URL parameters or referral data. Here's how you can set it up:
utm_source
, utm_medium
, or referrer_url
.Insert JavaScript to extract URL parameters and set them into the hidden fields.
tag area:
<script>document.addEventListener("DOMContentLoaded", function() { const params = new URLSearchParams(window.location.search); // Set UTM parameters if they exist document.querySelectorAll("input[name='utm_source']").forEach( input => input.value = params.get('utm_source') || '' ); document.querySelectorAll("input[name='utm_medium']").forEach( input => input.value = params.get('utm_medium') || '' ); document.querySelectorAll("input[name='utm_campaign']").forEach( input => input.value = params.get('utm_campaign') || '' ); // Capture and store referrer URL document.querySelectorAll("input[name='referrer_url']").forEach( input => input.value = document.referrer );});</script>
https://yourwebsite.com/form-page?utm_source=google&utm_medium=cpc&utm_campaign=spring_sale
If users navigate between pages before submitting the form, store UTM parameters using localStorage
:
<script>document.addEventListener("DOMContentLoaded", function() { const params = new URLSearchParams(window.location.search); // Save UTM parameters in localStorage ['utm_source', 'utm_medium', 'utm_campaign'].forEach(param => { if (params.get(param)) localStorage.setItem(param, params.get(param)); }); // Retrieve stored values and set hidden fields document.querySelectorAll("input[name='utm_source']").forEach(input => input.value = localStorage.getItem('utm_source') || '' ); document.querySelectorAll("input[name='utm_medium']").forEach(input => input.value = localStorage.getItem('utm_medium') || '' ); document.querySelectorAll("input[name='utm_campaign']").forEach(input => input.value = localStorage.getItem('utm_campaign') || '' );});</script>
localStorage
.This ensures that your Webflow form captures valuable source-tracking data for marketing and analytics.