onza / CookieConsent

A simple cookie consent manager (opt-in)
https://onza.github.io/CookieConsent/
MIT License
5 stars 0 forks source link

How to add a Facebook Pixel in the settings opt-in and out #8

Open gh4l3b opened 2 years ago

gh4l3b commented 2 years ago

I want to add Facebook Pixel and remove Youtube and Parot? Also is it possible to put the settings inside the data policy page instead of popup window?

Thank you

onza commented 2 years ago

You can adapt the script to your needs by deleting the associated parts from Pardot and YouTube and adding a specific FB Pixel consent script.

gh4l3b commented 2 years ago

You can adapt the script to your needs by deleting the associated parts from Pardot and YouTube and adding a specific FB Pixel consent script.

Thank you @onza Can you show me an example where should I place the Pixel script in the code?

gh4l3b commented 2 years ago

Hi @robindanzinger @onza I have found this issue #5 and it helped alot. However the Facebook script is in google tag manager and I want to enable or disable it from the cookie settings checkbox. is this possible? Please if yes can you show me how to do it. this is the script in google tags added as custome html.

<!-- Facebook Pixel Code -->
<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', 'xxxxxxxxxxxxxxx');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxxxxxx&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
onza commented 2 years ago

We don't need FB Pixel currently. Sorry we don't have time to add that at the moment, maybe in the future. As already shown in the CookieConsent.js for Pardot and GA, you have to write a function to enable and disable FB. Then add this to the banner above. With a little knowledge of JS and the Pixel cookie you can do it for sure.