Facebook Pixel (consent mode)

Facebook Pixel offers methods to enable or disable consent mode based on whether or not the user has consented to the suitable cookie category. Currently the implementation is not built in as the suitable category may vary depending on how you use Facebook Pixel on your site.

It’s however easy to implement with a few changes to the implementation code.

How to implement the Facebook Pixel consent mode with CookieHub

1. Add the fbq(‘consent’…) line to your Facebook Pixel code above the init method as shown below:

<!-- Facebook Pixel Code -->
s.parentNode.insertBefore(t,s)}(window, document,'script',
fbq('consent', 'revoke');
fbq('init', 'xxxxxxxxxxxxxxxxxxx');
fbq('track', 'PageView');
<!-- End Facebook Pixel Code -->

2. Add the onAllow and onDeny triggers to your CookieHub implementation code:

<script type="text/javascript">
var cpm = {
  onAllow: function(category)
    if (category == 'marketing')
      fbq('consent', 'grant');
  onRevoke: function(category)
    if (category == 'marketing')
      fbq('consent', 'revoke');
var d=h.getElementsByTagName("script")[0],e=h.createElement("script");

In this example, Facebook Pixel is allowed when the user allows the marketing category. If you would like to use the analytics instead, simply replace marketing with analytics.

Still need help? Contact Us Contact Us