Jump to content

Stop Facebook Pixel triggering until consent is obtained (GDPR, EU Cookie Law)

Recommended Posts

Interested to know if anyone has successfully blocked Squarespace's integration of Facebook Pixel from firing page views until consent has been obtained by the user?

Facebook's GDPR page recommends injecting this snippet to revoke consent until it is obtained and before the page view triggers:

fbq('consent', 'revoke');

The issue I'm having is that if I run that in a Code Injection before Squarespace's integrated Pixel code runs, the 'fbq' Javascript function is not defined yet. If I run it afterwards, the Pixel has already fired before consent has been obtained.

I'm after a pure Javascript solution to this; not interested in using a paid plugin.

Link to comment
  • Replies 2
  • Created
  • Last Reply

I personally don’t know the solution with pure JavaScript however Style Factory wrote a blog post on how to achieve this with CookiesPro which is free if you have under 100 pages on your website. Obviously this won’t be any good for you if your website has more than 100 pages. 
 

https://www.stylefactoryproductions.com/blog/create-gdpr-compliant-squarespace-cookie-banner

Link to comment

Hi @wesgardner.  The issue you're having makes sense because fbq('consent', 'revoke'); needs to happen after fbq is initialized but before fbq("track"...) is run. When you're using Squarespace's built-in integration, you can't get "between" those two with your own code.

To work around it, you'll want to stop using the built-in integration and instead insert the FB tracking code on your own, via code injection. Then you can work with it with more granularity. The next step is detecting when the user consents via Squarespace's built-in cookie banner. Looking past the shortfalls of this banner in terms of compliance, this can be done a number of ways.

Are you also using Google Analytics? A similar approach would apply there, and could be handled together in the same script. GA doesn't offer a "grant consent" method like FB does, but that's not a big deal.

Do you have a template with AJAX loading and is it enabled? In theory, Facebook should deal with this itself since it uses the history state API listener, but GA (if you're using it) would require updating the page_path parameter.

-Brandon

If a response helped you out, send a 'Like' 👍 (bottom-right) and/or 'Upvote' vote.jpg.c260784ece77aec852b0e3049c77a607.jpg (top-left)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.