Cookies disappear on page refresh

My intention is to read utm parameters from the home page link and store them as cookies to later read them and redirect the user to a form with the parameters.
I am setting cookies with the following code inside the head tag:

function setCookie(cname,cvalue,exdays) {
const d = new Date();
d.setDate(d.getDate() + exdays);
let expdate = d.toUTCString();
document.cookie = cname + “=” + cvalue + “; expires=” + expdate + “;path=/”;

console.log('cookie saved: ')
console.log(cname + “=” + cvalue + “; expires=” + expdate + “;path=/”)
}
setCookie(‘utm_parameters’, JSON.stringify(utm_parameters), 90)

When I go to a different page or reload the home page without parameters the cookie is gone. The same code works on localhost, but not in webflow.
Update: in the application tab in chrome one can see the cookie appear and disappear in split second