-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoogle-analytics.html
34 lines (27 loc) · 1.02 KB
/
google-analytics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{% if site.google_analytics %}
<script>
if (!navigator.doNotTrack) {
// https://stackoverflow.com/questions/3973441/conditionally-load-javascript-external-and-internal-and-keep-execution-order
script = document.createElement('script');
script.type = "text/javascript";
script.src = 'https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}'
// Ugly and increases page size. Oh well.
document.head.appendChild(script);
}
</script>
<script>
// Respect DNT
// This should work even if navigator.doNotTrack is not defined?
if (!navigator.doNotTrack) {
//
// https://medium.com/swlh/how-to-use-google-tag-manager-and-google-analytics-without-cookies-7d041c73cc76
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics }}', {
'client_storage': 'none',
'anonymize_ip': true,
});
}
</script>
{% endif %}