Optional: send visit history to HubSpot
HubSpot can show which pages a visitor looked at before filling in your form. For that, each submission needs HubSpot's visitor cookie. This small script copies it into the form when the visitor clicks submit.
<script>
document.addEventListener("submit", function (event) {
var form = event.target;
var cookie = document.cookie.match(/(?:^|;\s*)hubspotutk=([^;]+)/);
if (!cookie || form.tagName !== "FORM") return;
var input = form.querySelector('input[name="hutk"]');
if (!input) {
input = document.createElement("input");
input.type = "hidden";
input.name = "hutk";
form.appendChild(input);
}
input.value = cookie[1];
}, true);
</script>
In Webflow, open Site settings > Custom code, paste it into Footer code, save, and publish the site.
Good to know
- The cookie only exists when HubSpot's tracking code is also on your site. Without it, submissions still reach HubSpot, just without visit history.
- Custom code needs a paid Webflow site plan.
- HubSpot's tracking code can also collect your Webflow forms by itself ("non-HubSpot forms"), which sends each submission twice. The setup checks of each paired form tell you if that is on.
- Some ad blockers stop the cookie. Those submissions still arrive, without visit history.