Set referring URL as hidden input
A method to pass the referring domain/URL as a hidden field in a form in Webflow. This is perfect to know who referred the person submitted the form, or a way to display the referring domain on the page on your Webflow site.
A method to pass the referring domain/URL as a hidden field in a form in Webflow. This is perfect to know who referred the person submitted the form, or a way to display the referring domain on the page on your Webflow site.
How to add it
- Add the Javascript code snippet to the closing body tag on your Webflow page settings
- Add a field to your form
- Update the forms hidden field by the element ID, in this code example hidden-field
- Set the field to display none
The code
Javascript
// Make a reference to the form field
<script>
const hiddenField = document.getElementById('hidden-field');
// Get the referrer domain
const referrer = document.referrer.split('/')[2];
// If there is a referrer then set the field value
if (referrer) {
hiddenField.value = referrer;
}
</script>