APIs & Integrations

MZA_SandY
Member

Facebook and LinkedIn Pixels from Firing Before Consent with HubSpot and OneTrust Cookie Banner

SOLVE

Hi everyone,

 

I’m experiencing an issue where Facebook and LinkedIn pixels are firing on my site before users have given consent. I’m using HubSpot’s native Ads Management integration to connect these platforms, along with Google Ads, and OneTrust CMP to manage user consent.

 

I followed the HubSpot Cookie Banner API documentation and implemented a script using _hsq.push(['doNotTrack']) to block all tracking by default, enabling it only after consent is granted. While Google Ads behaves as expected (does not fire until consent is granted), Facebook and LinkedIn pixels are still firing prematurely (https://js-eu1.hsadspixel.net/fb.js for Facebook and px.ads.linkedin.com for LinkedIn).

 

Has anyone successfully resolved this issue or used OneTrust CMP with HubSpot Ads Management to ensure all pixels respect consent?

 here is my script for Onetrust : 
 "

<!-- OneTrust Cookies Consent Notice start for skillandyou.com -->
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
type="text/javascript" charset="UTF-8"
data-domain-script="78232b22-5983-4ccb-ac52-a917af20b765">
</script>

<script type="text/javascript">
// Initialize the HubSpot tracking array
var _hsq = _hsq || [];
_hsq.push(['doNotTrack']); // Default to "Do Not Track"

// Function to notify HubSpot about consent
function OptanonWrapper() {
if (OnetrustActiveGroups.includes("C0004")) { // Ensure C0004 matches your OneTrust group for tracking
// Inform HubSpot that consent is granted for tracking
_hsq.push(['doNotTrack', { track: true }]);
} else {
// Inform HubSpot that tracking should remain disabled
_hsq.push(['doNotTrack']);
}
}

// Listen for consent changes
document.addEventListener('OneTrustGroupsUpdated', function() {
OptanonWrapper();
});
</script>
<!-- OneTrust Cookies Consent Notice end for skillandyou.com -->"

Any guidance would be greatly appreciated.

 

Thank you!

0 Upvotes
1 Accepted solution
AnzeKoprivec
Solution
Member

Facebook and LinkedIn Pixels from Firing Before Consent with HubSpot and OneTrust Cookie Banner

SOLVE

Cookie scripts can be wierd and it tends to be hard to manage them programaticly, you also didn't include any of the code of how you add those pixels in so its hard to debug without seeing it.

The easiest way I've found to manage cookies is either only load the script in once consent has been granted, rather than loading it in initially and trying to disable it. 

A better approach all together would be to have google tags manage your pixels and set it up there so that once OneTrust cookie banner gets accepted the rest of the tags that house the other pixels get added to the user seassion - this is a really common approach when it comes to managing multiple tracking pixels, you can also add your code that enable HubSpot tracking in there.


If my post helped answer your query, please consider marking it as a solution.

View solution in original post

0 Upvotes
2 Replies 2
AnzeKoprivec
Solution
Member

Facebook and LinkedIn Pixels from Firing Before Consent with HubSpot and OneTrust Cookie Banner

SOLVE

Cookie scripts can be wierd and it tends to be hard to manage them programaticly, you also didn't include any of the code of how you add those pixels in so its hard to debug without seeing it.

The easiest way I've found to manage cookies is either only load the script in once consent has been granted, rather than loading it in initially and trying to disable it. 

A better approach all together would be to have google tags manage your pixels and set it up there so that once OneTrust cookie banner gets accepted the rest of the tags that house the other pixels get added to the user seassion - this is a really common approach when it comes to managing multiple tracking pixels, you can also add your code that enable HubSpot tracking in there.


If my post helped answer your query, please consider marking it as a solution.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Facebook and LinkedIn Pixels from Firing Before Consent with HubSpot and OneTrust Cookie Banner

SOLVE

Hi, @MZA_SandY! Thank yo very much for your question and for including all your details 💪 I'd like to invite some of our community champions to the converstaion — hey @TomM2 @evaldas @Markestac, do you have any suggestions or other troubleshooting tips for @MZA_SandY

 

Thank you very much for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes