Yes indeed it was easyer than I was thinking :)
I also done a change to be more RGPD compliant. Google analytics tracking code are not set by default but is working as soon as cookies are accepted not only on page refresh. But I had to also check if the body had the class ‘cookie-accepted’ to get the code working allways if cookies were accepted.
<script>
enableGoogleAnalytics = function(event) {
//placer le code analytics ici
var IdAnalytics = 'XX-XXXXX-XX'; //modifier l'id ICI
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', IdAnalytics, 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
//fin analytics
}
</script>
<script>
$(document).on('setCookieNotice', function(event) {
enableGoogleAnalytics();
});
$(document).ready(function($) {
if($('body').hasClass('cookies-accepted')){
enableGoogleAnalytics();
}
});
</script>
Thank you for your help Bartosz !