Then we take back the function that allows the launch of scripts located in the Axeptio back office and we configure it so that the function will only be called if the user choose Facebook Pixel or Google Analytics
We will now just add the full script right after the SDK which will look like this
<scripttype="text/javascript">//Le sdk qui permet de lancer le widget Axeptio et de sauvegarder les acceptations var el = document.createElement('script'); el.setAttribute('src', 'https://static.axept.io/sdk.js'); el.setAttribute('type', 'text/javascript'); el.setAttribute('async', true); el.setAttribute('data-id', '5da587fd629c0c21f3249270'); el.setAttribute('data-cookies-version', 'croquorico_VersionProdFR'); if (document.body !== null) {document.body.appendChild(el); }// La fonction qui permet de lancer Google Analyticsfunction launchGoogleAnalytics(){ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*newDate();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-124590402-1','auto');ga('send','pageview');}// La fonction qui permet de lancer le Facebook Pixelfunction launchFB(){!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','1380554325421888');fbq('track',"PageView");}// La fonction qui relie Axeptio au lancement du cookie le Facebook Pixel et à Google Analyticsvoid 0 === window._axcb && (window._axcb = []);window._axcb.push(function(axeptio) {axeptio.on("cookies:complete",function(choices) {if(choices.facebook_pixel) {launchFB(); }if(choices.google_analytics) {launchGoogleAnalytics(); } });});</script>
Congrats ! Now your Google Analytics and Facebook Pixel cookies only deposit if the user agrees to them