Usercentrics - PUBLIC

How can I block the HubSpot tracking code (non-essential analytic cookies)?

The HubSpot tracking code is unique to each HubSpot account and allows HubSpot to monitor customers website traffic. The tracking code is automatically included on HubSpot blog posts, landing pages, and website pages. If you have any externally hosted pages (i.e., pages not on HubSpot), you must install the HubSpot tracking code manually to capture analytics for those pages.

The HubSpot tracking code is unique to each HubSpot account and allows HubSpot to monitor customers website traffic. The tracking code is automatically included on HubSpot blog posts, landing pages, and website pages. If you have any externally hosted pages (i.e., pages not on HubSpot), you must install the HubSpot tracking code manually to capture analytics for those pages.

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 but these 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 tracking/analytics cookies, HubSpot provide 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.
Linking more detail from HubSpot public documentation.


How does it work with the usercentrics dataLayer

Standard Package

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

2. Use the code below:

Please keep in mind, 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 and Enterprise Package

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

2. Use the code below:

Please keep in mind, 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?

 

Usercentrics - PUBLIC