We are looking into some projects where we would need to access HubSpot cookie ID. We are not sure yet which solution we may use and it's possible that we will just use our custom code.
function getHubSpotCookie() {
const name = ""hubspotutk="";
const decodedCookie = decodeURIComponent(document.cookie);
const cookies = decodedCookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let c = cookies[i].trim();
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return null;
}
const hubspotutk = getHubSpotCookie();
console.log(""HubSpot Cookie ID to send:"", hubspotutk);
Now you can use it as per your requirement."
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member. Thanks!
function getHubSpotCookie() {
const name = ""hubspotutk="";
const decodedCookie = decodeURIComponent(document.cookie);
const cookies = decodedCookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let c = cookies[i].trim();
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return null;
}
const hubspotutk = getHubSpotCookie();
console.log(""HubSpot Cookie ID to send:"", hubspotutk);
Now you can use it as per your requirement."
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member. Thanks!
Also, I have found this similar post that might help you, more precisely, the solution from @ModuleMaestro on this post "HubSpot Cookie".
Let me know if that helped?
Have a great day! 🌞 Bérangère
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.