APIs & Integrations

michaelhubspot
Member

Manually invalidating user cookie token?

Hi there!

I was wondering if Hubspot provides a javascript api to invalidate or regenerate tracking cookies stored. For example, if a user logs out of an account and another user logs on, I would like a way to regenerate the cookie hubspotutk token so that the second user can have tracking associated with their Contact record and not the first user.

I see a list of cookies Hubspot adds here: https://knowledge.hubspot.com/articles/kcs_article/reports/what-cookies-does-hubspot-set-in-a-visito... Should I manually expire or delete these cookie(s)? Do I need to notify Hubspot’s tracking scripts that the cookie has expired?

Thank you for any help on this (or let me know if this a duplicate and I will merge / take it down).
-Michael

0 Upvotes
2 Replies 2
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Manually invalidating user cookie token?

Hi @michaelhubspot,

When a user logs out, you could remove the hubspotutk cookie from their browser using something like $cookies.remove('hubspotutk') When a user logs in, you could identify them using the Tracking Code API (see documentation below). The following forum post also touches on some of the same methods, and is worth a read:

Hi there, We have a similar issue, we hope you can help with. -We use AngularJS which is Single Page Application (SPA) In a normal webpage system the HUBSPOT javascript plugin, reloads when each page loads -Now in our SPA application the page never really reloads/refreshes the view. -So we use the standard AngularJS handler which basically fires on each page load it’s called stateChangeSuccess $rootScope.$on(’$stateChangeSuccess’, function _hsq.push(["identify", { email: cur…

0 Upvotes
michaelhubspot
Member

Manually invalidating user cookie token?

Thank you @Derek_Gervais, this should work for my use case.