APIs & Integrations

MTarnopolska
Contributor

How to access cookie ID

SOLVE

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

1 Accepted solution
GRajput
Solution
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

How to access cookie ID

SOLVE

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!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


View solution in original post

2 Replies 2
GRajput
Solution
Recognized Expert | Gold Partner
Recognized Expert | Gold Partner

How to access cookie ID

SOLVE

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!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


BérangèreL
Community Manager
Community Manager

How to access cookie ID

SOLVE

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! 🌞
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.


Saviez vous que la Communauté est disponible en français?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres! !
0 Upvotes