Manage your cookies in custom mode

If you don't have a developer in your team, we recommend that you use Google Tag Manager (free tool 100% free provided by Google : tagmanager.google.com)

CUSTOM JAVASCRIPT INTEGRATION A "cookies:complete" event is dispatched.

1. Video presentation

2. Cookies integration

Before going throught this step, it is necessary that you followed the sdk integration part and finished the configuration of the cookies that you want to add. If this isn't done you can check :

List all cookies that you want to add and go to your website backoffice.

Let's take the hubspot tag for example

Loading code given by Hubspot.
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/XXXXXXX.js"></script>
<!-- End of HubSpot Embed Code -->

It is HTML code so we can't use it that way. We have to translate it to Javascript The login given in the script URL corresponds to the client ID that allows Hubspot to identify your account. We chose to add it as a parameter to be clearer.

function loadHubspot(clientId) {
  var el = document.createElement('script');
  el.setAttribute('id', 'hs-script-loader');
  el.setAttribute('type', 'text/javascript');
  el.setAttribute('async', true);
  el.setAttribute('defer', true);
  el.setAttribute('src', '//js.hs-scripts.com/'+clientId+'js');
  document.body.append(el);
}

You can then copy paste the function on your back office and the script will be loaded on your site. Now you juste have to configure the cookie deposit on click on the Axeptio cookie widget. For this :

void 0 === window._axcb && (window._axcb = []);
window._axcb.push(function(axeptio) {
  axeptio.on("cookies:complete", function(choices) {
    if(choices.hubspot) {
      loadHubspot(0000000);
    }
  })
});

A fully clear, informed and unambiguous consent is necessary before the cookie deposit on the site 👊

3. Example for Google Analytics

Go search the Google Analitycs script.

Loading code given by Google Analytics.
<!-- Start of Google Analytics -->
<script>
  (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*new Date();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-00000000-1', 'auto');
  ga('send', 'pageview');
 
</script>
<!-- End of Google Analytics --> 

You now translate it to Javascript so you can copy and paste the function to your back office. Now all there is left is to configure the cookie deposit on click on the Axeptio cookie widget, which gives :

function launchGA() {
  (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*new Date();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-00000000-1', 'auto');
  ga('send', 'pageview');
}
  
void 0 === window._axcb && (window._axcb = []);
window._axcb.push(function(axeptio) {
  axeptio.on("cookies:complete", function(choices) {
    if(choices.google_analytics) {
      launchGA();
    }
  })
});

4. Example for the Facebook pixel and Google analytics

Go search the Facebook Pixel script :

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

You now translate it to Javascript so you can copy and paste the function to your back office. Now all there is left is to configure the cookie deposit on click on the Axeptio cookie widget, which gives :

function 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', '159702201342042');
  fbq('set','agent','tmgoogletagmanager', '159702201342042');
  fbq('track', "PageView");
}

function 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*new Date();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-00000000-1', 'auto');
    ga('send', 'pageview');
}
    
void 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();
   }
  });
});

Congratulations ! Everythings works perfectly ! 🤘

Dernière mise à jour