Hubspot Integration

Have more questions? Submit a request

Hubspot is one of the most popular CRM systems and offers a cookie banner by default. However using it by European companies is not GDPR compliant. You can use the CookieFirst cookie banner together with Hubspot. 

 

There are multiple ways of using Hubspot, often people use Hubspot tracking on their websites but can also make use of Hubspot landingpages. By default there are multiple cookies set before getting consent of the user. 

Using Hubspot in your website

You would place a Hubspot script in your website to enable the functionality. If you also use the CookieFirst banner you can use the following helper script to manage the Hubspot cookies.

In the example below we have tied the Hubspot tracking to the "Functional" category of the banner. You can replace it with another category if you want. 

The script makes use of the Hubspot cookie API, we only allow the cookies of Hubspot be set when consent to the functional category is given, if it is revoked we remove the cookies with the API.

You can put this script directly after your Hubspot embed code.

<script>
      (function () {
        // Variable if page should reload to reinit hubspot
        var shouldReload = false;

        function callbackFnc(e) {
          var consent = e.detail || {};

          var _hsq = (window._hsq = window._hsq || []);
          var _hsp = (window._hsp = window._hsp || []);

          // Check if functional is accepted replace functional with: performance or advertising to use a different category
          if (!consent.functional) {
            // If not
            // Either remove all Hubspot cookies or leave them and set doNotTrack cookie
            // _hsq.push(["doNotTrack"]);
            // _hsp.push(["doNotTrack"]);

            _hsp.push(["revokeCookieConsent"]);
            _hsq.push(["revokeCookieConsent"]);

            shouldReload = true;
          } else {
            _hsp.push(["doNotTrack", { track: true }]);
            _hsq.push(["doNotTrack", { track: true }]);

            if (shouldReload) {
              window.location.reload();
            }
          }
        }

        window.addEventListener("cf_consent", callbackFnc);
        window.addEventListener("cf_consent_loaded", callbackFnc);
      })();
    </script>

Articles in this section

Was this article helpful?
0 out of 0 found this helpful
Share