Cookie Google Analytics
You only have a Google Analytics cookie and you don't want to use Google Tag Manager to install it.

1. New Google Analytics cookie integration

A - Locate it on your website

Here is the code that activates Google Analytics and that you should have in your site Header
1
<script
Copied!

B - The Analytics function

We'll now transform the script and encapsulate it in a function that will launch the script (the launchGA() function).
1
function launchGA(){
2
var el = document.createElement('script');
3
el.setAttribute('type', 'text/javascript');
4
el.setAttribute('async', true);
5
el.setAttribute('src', '//www.googletagmanager.com/gtag/js?id=UA-234217-21');
6
document.body.append(el); window.dataLayer = window.dataLayer || [];
7
function gtag(){dataLayer.push(arguments);}
8
gtag('js', new Date());
9
gtag('config', 'UA-234217-21', { 'anonymize_ip': true });
10
gtag('config', 'UA-234217-21', {'link_attribution': true});
11
}
Copied!

C - Integration on your website

You'll just have to add it
1
function launchGA(){
2
var el = document.createElement('script');
3
el.setAttribute('type', 'text/javascript');
4
el.setAttribute('async', true);
5
el.setAttribute('src', '//www.googletagmanager.com/gtag/js?id=UA-234217-21');
6
document.body.append(el); window.dataLayer = window.dataLayer || [];
7
function gtag(){dataLayer.push(arguments);}
8
gtag('js', new Date());
9
gtag('config', 'UA-234217-21', { 'anonymize_ip': true });
10
gtag('config', 'UA-234217-21', {'link_attribution': true});
11
}
12
13
14
// La fonction qui relie Axeptio au lancement du cookie Google Analytics
15
void 0 === window._axcb && (window._axcb = []);
16
window._axcb.push(function(axeptio) {
17
axeptio.on("cookies:complete", function(choices) {
18
if(choices.google_analytics) {
19
launchGA();
20
}
21
});
22
});
Copied!
Great ! Everything works 👌
Last modified 11mo ago