Hi there,
I’m trying to load tracking codes for Google Tag Manager, Facebook, etc after receiving user consent via Hubspot cookie consent banner.
According to this page https://legacydocs.hubspot.com/docs/methods/tracking_code_api/get_consent_status it’s possible to do it in the following way:
var _hsp = window._hsp = window._hsp || [];
_hsp.push(['addPrivacyConsentListener', function(consent) {
if (consent.allowed) {
// Google Tag Manager tracking code
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXX');
// Facebook tracking code.....
}
}]);
[The example above uses HubSpot’s older consent-listener documentation. Developers should check the current Cookie Banner and Tracking Code documentation before implementing consent-dependent scripts.]
I’m getting an error:
leadflows.js:12 Uncaught Error: Multiple lead flow scripts are trying to run on the current page. Only the first one will be executed. The rest are ignored.
Could you please advise how to load multiple tracking codes?
Moderator Note: this post was reviewed for relevancy and optimized for clarity on October 23, 2026. Thank you for your contributions to the HubSpot Community!