Cookie control via consent

Esteemed Contributor

Having read through the huspot gdpr playbook, there are js tracking functions to check if cookie consent is either true or false.


Is there any reason why these endpoints could not be used to govern wether or not additional first or thrid party scripts are loaded?


I'm thinking of using the value set in the cookie `__hs_opt_out` as a event trigger to google tag manager load additional scripts if the value is set to `no`.


I've been looking at some cookie control services and wonder wether hubspots provision would be sufficient.




3 Replies 3
New Contributor

Have you tested this idea? If so, I would love to hear if it worked. 


I took the opposite approach and am trying to set cookie consent with Google Tag Manager and then loading services via GTM when the cookie has been set. However adding the Hubspot tracker with GTM seems to be affecting the Hubspot data. Hubspot seems to be loadig fine with GTM if I inspect the network, but our Hubspot Analytics reporting shows an odd flatline. 

Esteemed Contributor

I've abandoned using the above methods for the time being. They dont appear to offer what I was expecting.

Unless I can set the _hsq variable first.

var _hsq = _hsq || [];

I'm going for another method of using a custom html tag (containing javascript) in google tag manager. This checks to see if the hubspot opt out cookie exists `__hs_opt_out` and then checks the cookie value yes/no.


If the cookie is set dataLayer.push custom event is fired in tag manager. When tag manager detects the event and the event value matches the required value. It loads the analytics code.


If the cookie doesn't exist , a settimeout function waits for the accept button to appear.

Once the button appears - if a user clicks on accept, the cookie check functtion runs again.


I have a working draft, I need to test this thoroughly .After spending the day looking at the behavoir of the hubspot cookie consent tool there are 4 scenarios i need to consider for the script

  1. no cookies enabled
  2. cookies enabled
  3. cookies enabled, but notification is show - automatically sset the cookie value to no
  4. notification and consent required show cookies - accept set cookie value to no, decline sets it to yes.

I'm not clear on is recording of consent, wether that is a legal requirement. Services like cookiebot and onetrust record a users consent.

Also, I need guidance or if we need to offer granular options to a user, allowing them what type of cookies to allow.


The whole thing is a mine field, and whilst hubspots tools are good, their arrival at the 11th hour is a real pain.

Regular Contributor

Hi Matt, 

Any progress or with this? Would love to here how it went, and how to implement this with Google Tag Manager