Skip to content

Commit 8e57881

Browse files
authored
Update analytics.html
1 parent b7a9f84 commit 8e57881

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

_includes/analytics.html

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,58 @@
1+
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
2+
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
13
<script>
2-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
3-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
4-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
5-
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
4+
var gaProperty = '{{site.google_analytics}}';
65

7-
ga('create', '{{ site.google_analytics }}', 'auto');
8-
ga('send', 'pageview');
6+
// Disable tracking if the opt-out cookie exists.
7+
var disableStr = 'ga-disable-' + gaProperty;
8+
9+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
10+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
11+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
12+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
913

14+
ga('create', '{{ site.google_analytics }}', 'auto');
15+
ga('send', 'pageview');
16+
17+
window.addEventListener("load", function(){
18+
window.cookieconsent.initialise({
19+
"palette": {
20+
"popup": {
21+
"background": "#333333"
22+
},
23+
"button": {
24+
"background": "#ea2f10"
25+
}
26+
},
27+
"position": "bottom-left",
28+
"type": "opt-out"
29+
})});
30+
31+
onInitialise: function (status) {
32+
var type = this.options.type;
33+
var didConsent = this.hasConsented();
34+
if (type == 'opt-out' && !didConsent) {
35+
window[disableStr] = true;
36+
}
37+
},
38+
39+
onStatusChange: function(status, chosenBefore) {
40+
var type = this.options.type;
41+
var didConsent = this.hasConsented();
42+
if (type == 'opt-out' && !didConsent) {
43+
window[disableStr] = true;
44+
}
45+
},
46+
47+
onRevokeChoice: function() {
48+
var type = this.options.type;
49+
if (type == 'opt-in') {
50+
window[disableStr] = true;
51+
}
52+
if (type == 'opt-out') {
53+
window[disableStr] = false;
54+
}
55+
},
56+
1057
</script>
58+

0 commit comments

Comments
 (0)