How can I capture, store, and pass UTM parameter values as hidden fields through a Webflow form?

Published on
September 22, 2023

To capture, store, and pass UTM parameter values as hidden fields through a Webflow form, you can follow these steps:

  1. Start by creating the form in Webflow:
  • Drag and drop a Form element onto your page.
  • Add the necessary form fields, such as Name and Email.
  1. Add hidden fields for the UTM parameters:
  • Drag and drop a Field element onto the form.
  • Double-click the field to open the settings panel.
  • In the "Field Type" dropdown, select 'Hidden' to make it a hidden field.
  • In the "Field Name" input, enter the name of the UTM parameter (e.g., 'utm_source').
  1. Fetch the UTM parameter value using JavaScript:
  • Open the Page Settings for your form page.

  • In the Custom Code section, add a <script> tag.

  • Insert the following JavaScript code within the <script> tags:

    \`\`\`javascript<script>  function getParameterByName(name, url) {    if (!url) url = window.location.href;    name = name.replace(/[[]]/g, '\\$&');    var regex = new RegExp('[?&]' + name + '(=([^&#]\*)|&|#|$)'),        results = regex.exec(url);    if (!results) return null;    if (!results[2]) return '';    return decodeURIComponent(results[2].replace(/+/g, ' '));  }  var utm_source = getParameterByName('utm_source');  var utm_medium = getParameterByName('utm_medium');  var utm_campaign = getParameterByName('utm_campaign');  document.getElementById('utm_source').value = utm_source;  document.getElementById('utm_medium').value = utm_medium;  document.getElementById('utm_campaign').value = utm_campaign;</script>\`\`\`Make sure to adjust the `utm_source`, `utm_medium`, and `utm_campaign` variables to match the names of your UTM parameters.
  1. Update the form field IDs:
  • Go back to your form in Webflow.
  • Open the field settings panel for each hidden field (e.g., utm_source).
  • In the "Field ID" input, give each field a unique ID that matches the IDs used in the JavaScript code (e.g., 'utm_source').
  1. Test the form:
  • Publish your website and test the form by submitting it.
  • Check if the hidden field values are being captured correctly on form submission, including the UTM parameter values.

By following these steps, you'll be able to capture, store, and pass UTM parameter values as hidden fields through a Webflow form. This allows you to gather valuable UTM data without requiring users to manually input the information.

Additional Questions:

  1. How can I track UTM parameters in Webflow?
  2. Can I integrate Google Analytics with Webflow forms?
  3. How do I use JavaScript to manipulate form data in Webflow?