How to record cookies into your form

Hubspot uses browser cookies like hubspotUtk and Marketo uses one called _mkto_trk to coordinate campaign and other information about your users and you’d like to capture that information in your form submissions so you can know where that user came from.

With a little javascript you can capture those values and store them into the form before sending it to FormKeep where it will be saved along with everything else the user enters into your form.

<!-- Add a  hidden input field to your form -->
<input type="hidden" name="hubspot_cookie" value="">
<!-- include your favorite getCookie function -->
<script>
// And some get cookie function like:
function getCookie(cname) {
  let name = cname + "=";
  let ca = document.cookie.split(';');
  for(let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

// Then set the field value before submitting the form and you're done!
document.getElementsByName("hubspot_cookie").value = getCookie('hubspotUtk');
</script>

There are many other js libraries that allow you to more easily read a cookie value, we’re just including a basic one here for your convenience.