Code

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.

Set referring URL as hidden input preview

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

  1. Add the Javascript code snippet to the closing body tag on your Webflow page settings
  2. Add a field to your form
  3. Update the forms hidden field by the element ID, in this code example hidden-field
  4. 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>

                    

Browse similar code snippets

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →