Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Table of Contents
includeindentclass
minLevel1
maxLevel34
outlinefalse
excludeOverview, Do you need further help?
typelist
printablefalse

HubSpot Essential Cookies

...

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:

...

Code Block
 <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:

...

Code Block
 <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?

...