APIs & Integrations

andre9000
Contributor

Callback once Cookie Banner is loaded

Hi guys,

for implementing our custom cookie banner solution, I am hiding the hubspot cookie banner and then simulate a click on the hidden HS banner. However, when my code executes, the HS banner is not loaded yet. Even if I execute my code on $(window).on('load', ...), the banner is not loaded yet.

Is there a callback or event that I can use to know once the banner is fully loaded? I came up with this code which triggers once the banner is appended to the DOM, however at that point the click event handlers are not attached to the HS Accept/decline buttons yet, so it doesn't work:

$(document).on('DOMNodeInserted', '#hs-eu-cookie-confirmation', function() {
    // click HS button...
  });

Best,
Andre

0 Upvotes
2 Replies 2
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Callback once Cookie Banner is loaded

Hi @andreks,

There isn't any event or callback related to the loading of the HubSpot privacy banner. The current design is more focused on using the HubSpot banner to collect consent, and then use the Tracking Code API methods to get that consent status to use for external purposes. If the timeout method works, you can go with that; otherwise I'd recommend checking out the related Tracking Code API methods instead:

Remove cookies

_hsq.push(['revokeCookieConsent']); - Remove the cookies created by the HubSpot tracking code that are included in the consent banner under GDPR.



0 Upvotes
andre9000
Contributor

Callback once Cookie Banner is loaded

It works if I set a timeout:

$(document).on('DOMNodeInserted', '#hs-eu-cookie-confirmation', function() {
  setTimeout(function() {
    // click banner...
  }, 300);
});

Still not the nicest solution though. Has anyone a better idea?

0 Upvotes