Below is a sample code that can be used to integrate Facebook Pixel with Cookie Consent. Make sure you insert your Facebook Pixel id and the correct url of your Cookie Consent javascript.


This code will make sure that Facebook Pixel will not set any tracking cookie for the user until he has consented.


<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', 'xxxxxxxxxxxxxxxxxxx');

  // Remove or comment the following line
  //fbq('track', 'PageView');
</script>
<script src="https://cookie.consent.is/cc/xxxxxxxx.js"></script>
<script type="text/javascript">
window.addEventListener("load", function() {
window.cookieconsent.initialise({
  onInitialise: function(status) {
    if (this.hasConsented('analytics')) {
      // User has already allowed the analytics category

      // Send Faebook Pixel page event
      fbq('track', 'PageView');
    }
  },
  onAllow: function(category) {
    if (category == 'analytics') {
      // User just allowed the analytics category

      // Send Faebook Pixel page event
      fbq('track', 'PageView');
    }
  }
})
});
</script>