Usercentrics - PUBLIC

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

HubSpot Essential Cookies

HubSpot does drop essential cookies that do not require consent on customers site pages. You can see a full list of these essential cookies here.

HubSpot Non-Essential Cookies

HubSpot can also drop non-essential analytic cookies that are controlled by a (cookie) consent banner. You can see a full list of these non-essential analytic cookies here.

In order to block HubSpot analytic/tracking cookies, HubSpot provides us with the _hsq.push(['doNotTrack']); function which places the __hs_do_not_track cookie in the visitors browser, which will prevent the HubSpot tracking code from sending any information for the visitor. More details can be found here.

How does it work with the Usercentrics dataLayer?

Standard Package

  1. Add the Data Layer Name e.g. dataLayer in the Usercentrics Admin Interface:

  2. Use the code below:

Please keep in mind that this is just an example, you need to adjust it based on your needs.

 <script>
  dataLayer = window.dataLayer || [];

  var _hsp = window._hsp = window._hsp || [];
  var _hsq = window._hsq = window._hsq || []
  
  _hsq.push(['doNotTrack']);
  console.log("HubSpot tracking disabled");
  
var waitForDataLayerObjHubSpot = function (dataLayer, callback) {
  if (dataLayer.length > 0) {
    callback();
  } else {
    setTimeout(function () {
      waitForDataLayerObjHubSpot(dataLayer, callback);
    }, 1000);
  }
};

waitForDataLayerObjHubSpot(dataLayer, function () {
  dataLayer.map(function (ele) {
    if (ele.event === 'consent_status') {
      if (ele['HubSpot'] === true) {
        console.log("consent is set to:", ele.event = ele['HubSpot']);
        console.log('HubSpot has consent');
        
		_hsq.push(['doNotTrack', {track: true}]);
        _hsp.push(['showBanner']);
        document.getElementById('hs-eu-confirmation-button').click();

        console.log("HubSpot banner confirmed");
        console.log("HubSpot tracking activated");
      } else {
        console.log('HubSpot has no consent');
        console.log("consent is set to:", ele.event = ele['HubSpot']);

        _hsq.push(['doNotTrack']);
        _hsp.push(['showBanner']);
        document.getElementById('hs-eu-decline-button').click();
        
        console.log("HubSpot banner declined");
        console.log("HubSpot tracking disabled");
      }
    }
    return ele;
  })
}); 
</script>

Business & Enterprise Package

  1. Add the Window Event Name e.g. ucEvents in the Usercentrics Admin Interface:

  2. Use the code below:

Please keep in mind that this is just an example, you need to adjust it based on your needs.

 <script>
        var _hsp = window._hsp = window._hsp || [];
        var _hsq = window._hsq = window._hsq || [];
      
        var waitTimeout = 0;
        var currentFunc = null;
      
        function waitForHubspotBanner(method, _currentFunc) {
          if (document.getElementById('hs-eu-confirmation-button') !== null) {
            if (currentFunc != _currentFunc) {
              console.log(currentFunc, _currentFunc);
              return;
            }
            method();
          } else {
            waitTimeout += 50;
            if (waitTimeout >= 10000) {
              console.log('wait timeout reached');
              return;
            }
            setTimeout(function () {
              console.log("no HubSpot Banner found");
              waitForHubspotBanner(method, _currentFunc)
            }, 50);
          }
        }
      
        window.addEventListener("ucEvents", function (e) {   //Window Event Name e.g. ucEvents
          // console.log('Consent Event fired');
          if (e.detail && e.detail.event == "consent_status") {
            // check for consent status of service "HubSpot"
            if (e.detail['HubSpot'] === true) {
              console.log('HubSpot has consent');
              _hsp.push(['showBanner']);
              _hsq.push(['doNotTrack', { track: true }]);
              console.log("do not Track unset");
      
              waitTimeout = 0;
              currentFunc = 'setConsent';
      
              waitForHubspotBanner(function () {
                document.getElementById('hs-eu-confirmation-button').click();
                console.log("HubSpot Banner confirmed");
      
              }, 'setConsent');
      
            } else {
      
              console.log('HubSpot has no consent');
              console.log("consent is set to false", e.detail)
              _hsp.push(['showBanner']);
      
              //_hsp.push(['revokeCookieConsent']);
      
              _hsq.push(['doNotTrack']);
              waitTimeout = 0;
              currentFunc = 'revokeConsent';
      
              waitForHubspotBanner(function () {
      
                document.getElementById('hs-eu-decline-button').click();
                console.log("HubSpot Banner declined");
                console.log("HubSpot banner declined and doNotTrack set");
      
              }, 'revokeConsent');
            }
          } else {
            console.log('no consent_status event');
          }
        });
      </script>

Do you need further help?

How can I get help with technical questions?

  • No labels