How to access cookie ID

Hello everyone,

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.

Thank you in advance!

Kind regards,

Mila

Hi @MTarnopolska, I hope that you are well!
Great question, thanks for asking the HubSpot Community!
For information around the topic, here are some resources that might be of interest:
- Cookies set in your visitor’s browser by HubSpot
- Track visitors in HubSpot
- Cookies set on HubSpot’s websites
- Cookie consent banner API
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! :sun_with_face:
Bérangère

Hi @MTarnopolska

"Here is the way to get Hubspotutk

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!