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
Add the Data Layer Name e.g.
dataLayer
in the Usercentrics Admin Interface: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
Add the Window Event Name e.g.
ucEvents
in the Usercentrics Admin Interface: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>