Integrating HubSpot Consent API with CookieYes

Last updated on April 28, 2025

Overview

This guide explains how to integrate CookieYes with the HubSpot Consent API to manage user consent seamlessly across both platforms. By establishing this connection, you can disable HubSpot’s default cookie banner and ensure HubSpot honours all consent preferences collected through CookieYes. This allows users to maintain a uniform consent experience while staying compliant with major global data privacy regulations, including GDPR, CCPA and ePrivacy Directive.

How It Works

When a user interacts with the CookieYes banner, either through the loading of the page or through an update of preferences, the script listens for two custom events: cookieyes_banner_load and cookieyes_consent_update. These events carry the user’s consent preferences for different cookie categories.

When either event triggers, the script maps the accepted categories from CookieYes to the categories that HubSpot expects. For example, CookieYes uses the term functional, which is translated to functionality to match HubSpot’s naming convention. These preferences are sent to HubSpot’s Consent API using the _hsp.push(['setHubSpotConsent', ...]) method.

By doing this, HubSpot receives real-time updates about the user’s consent state and activates only the approved categories of cookies. It avoids any further prompt for multiple consent prompts and guarantees that HubSpot tracking aligns with the user’s privacy choices as defined by CookieYes.

As part of the integration, HubSpot’s native cookie banner is disabled via window.disableHubSpotCookieBanner = true;. This step is crucial to ensure that only the CookieYes banner appears on the site without causing confusion or redundant consent collection.

Once the user grants consent, HubSpot respects the categories granted by the user and restricts cookie usage accordingly. Whether the cookies are for analytics, advertising, or functionality, HubSpot activates only the consented types. This approach helps your website stay compliant with regulations such as GDPR, CCPA, and ePrivacy, while maintaining user trust and tracking accuracy.

Implementation

Add the integration script.

Insert the following script into the <head> section of your webpage, above both CookieYes Script and the HubSpot tracking code. This ensures that the script passes consent to HubSpot before any tracking cookies load.

<script>
  // Disable HubSpot's default cookie banner
  window.disableHubSpotCookieBanner = true;
  window._hsp = window._hsp || [];

  // Updates HubSpot consent settings
  const setHubSpotConsent = (consentDetails) => {
    window._hsp.push(["setHubSpotConsent", consentDetails]);
  };

  // Maps CookieYes categories to HubSpot's consent format
  const getConsentDetails = ({ analytics, advertisement, functional }) => ({
    analytics: !!analytics,
    advertisement: !!advertisement,
    functionality: !!functional,
  });

  // Event listener for CookieYes banner load
  document.addEventListener("cookieyes_banner_load", ({ detail }) => {
    if (!detail || !detail.categories) {
      console.error("Invalid detail object:", detail);
      return;
    }

    setHubSpotConsent(
      getConsentDetails({
        analytics: detail.categories.analytics,
        advertisement: detail.categories.advertisement,
        functional: detail.categories.functional,
      })
    );
  });

  // Event listener for CookieYes consent update
  document.addEventListener("cookieyes_consent_update", ({ detail }) => {
    if (!detail || !detail.accepted) {
      console.error("Invalid detail object:", detail);
      return;
    }
    const acceptedCategories = new Set(detail.accepted);

    const consentDetails = {
      analytics: acceptedCategories.has("analytics"),
      advertisement: acceptedCategories.has("advertisement"),
      functionality: acceptedCategories.has("functional"),
    };

    setHubSpotConsent(consentDetails);
  });
</script>

Conclusion

By integrating CookieYes with HubSpot using this script, you consolidate consent control under a single, user-friendly banner and ensure that HubSpot respects user preferences. This provides a smoother user experience, avoids banner conflicts and helps you meet data privacy obligations with less effort.

Have more questions?

Reach out to us and we'll answer them.

Contact us