We are using the Forms API to send the hubspotutk value (the hutk parameter) to the API when it exists along with form data. We've found there are occassional errors in extracting this value from the browser's cookies, which causes a user to be unable to submit a form.
My question is whether there are additional checks we can add to our getCookie() function to make sure we've gotten a legit Hubspot cookie.
I see @WendyGoh posted this function. Is this still a recommended approach, and will it work even if there are multiple hubspotutk values in the cookie? Our priority is making sure users can submit a form, even if we don't send a hutk value.
function hubspotCookie() {
return document.cookie.replace(/(?:(?:^|.*;\s*)hubspotutk\s*\=\s*([^;]*).*$)|^.*$/, "$1");
}