Skip to content

Commit 016e40a

Browse files
authored
Merge pull request #100 from ByteInternet/cookie_consent
2 parents 547f63a + dd41df2 commit 016e40a

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

docs/_static/cookieconsent.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_static/css/colors.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_static/css/main.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
window.addEventListener('load', function() {
2+
const cc = initCookieConsent();
3+
4+
cc.run({
5+
current_lang: 'en',
6+
autoclear_cookies: true,
7+
page_scripts: true,
8+
force_consent: true,
9+
10+
onFirstAction: function(user_preferences, cookie) {
11+
// callback triggered only once on the first accept/reject action
12+
location.reload();
13+
},
14+
onAccept: function () {
15+
if (cc.allowedCategory('analytics')) {
16+
gtag('consent', 'update', {
17+
'analytics_storage': 'granted'
18+
});
19+
document.cookie = "cc_analytics=1";
20+
} else {
21+
document.cookie = "cc_analytics=0";
22+
}
23+
24+
if (cc.allowedCategory('targeting')) {
25+
gtag('consent', 'update', {
26+
'ad_storage': 'granted'
27+
});
28+
document.cookie = "cc_targeting=1";
29+
} else {
30+
document.cookie = "cc_targeting=0";
31+
}
32+
},
33+
onChange: function (cookie, changed_categories) {
34+
// callback triggered when user changes preferences after consent has already been given
35+
location.reload();
36+
},
37+
38+
gui_options: {
39+
consent_modal: {
40+
layout: 'box', // box/cloud/bar
41+
position: 'middle center', // bottom/middle/top + left/right/center
42+
transition: 'zoom', // zoom/slide
43+
},
44+
settings_modal: {
45+
transition: 'zoom' // zoom/slide
46+
}
47+
},
48+
49+
languages: {
50+
'en': {
51+
consent_modal: {
52+
title: 'Mmmm Cookies...',
53+
description: "Hypernode Docs uses cookies from Google to analyze activities on our website and to improve our documentation.<br><br>Read more about cookies in our <a href='https://www.hypernode.com/cookie-policy/' target='_blank' rel='noopener'>cookie policy</a> or take a look at our <a href='https://www.hypernode.com/privacy-policy/' target='_blank' rel='noopener'>privacy policy</a> to see how carefully we handle your personal data. If desired, you can change your preferences under ‘Preferences’.",
54+
primary_btn: {
55+
text: 'Accept all',
56+
role: 'accept_all'
57+
},
58+
secondary_btn: {
59+
text: 'Preferences',
60+
role: 'settings'
61+
}
62+
},
63+
settings_modal: {
64+
title: 'Mmmm Cookies...',
65+
save_settings_btn: 'Save preferences',
66+
accept_all_btn: 'Accept all',
67+
blocks: [
68+
{
69+
title: 'Functional',
70+
description: 'The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.',
71+
toggle: {
72+
value: 'necessary',
73+
enabled: true,
74+
readonly: true // cookie categories with readonly=true are all treated as "necessary cookies"
75+
}
76+
}, {
77+
title: 'Statistics',
78+
description: 'The technical storage or access that is used exclusively for statistical purposes.',
79+
toggle: {
80+
value: 'analytics',
81+
enabled: false,
82+
readonly: false
83+
},
84+
}, {
85+
title: 'Marketing',
86+
description: 'The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.',
87+
toggle: {
88+
value: 'targeting',
89+
enabled: false,
90+
readonly: false
91+
}
92+
}
93+
]
94+
}
95+
}
96+
}
97+
});
98+
});

docs/_static/js/cookieconsent.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_static/scss/colors.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
--message-info: #074E8A;
2525
--message-info-bg: #E7F2F8;
2626
--message-info-text: #063b67;
27+
--cc-btn-primary-bg: var(--primary-blue);
28+
--cc-btn-secondary-text: var(--primary-blue);
2729
}

docs/_templates/layout.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
3030
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
3131
{%- endif %}
32+
{%- if theme_analytics_id %}
33+
<link rel="stylesheet" href="{{ pathto('_static/cookieconsent.css', 1) }}" type="text/css" />
34+
{%- endif %}
3235
{%- for css in css_files %}
3336
{%- if css|attr("rel") %}
3437
<link rel="{{ css.rel }}" href="{{ pathto(css.filename, 1) }}" type="text/css"{% if css.title is not none %} title="{{ css.title }}"{% endif %} />
@@ -67,11 +70,23 @@
6770
<![endif]-->
6871

6972
{%- if theme_analytics_id %}
73+
<script>
74+
// Define dataLayer and the gtag function.
75+
window.dataLayer = window.dataLayer || [];
76+
function gtag(){dataLayer.push(arguments);}
77+
78+
gtag('consent', 'default', {
79+
'analytics_storage': 'denied',
80+
'ad_storage': 'denied'
81+
});
82+
</script>
7083
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
7184
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
7285
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
7386
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
7487
})(window,document,'script','dataLayer','{{ theme_analytics_id }}');</script>
88+
<script src="{{ pathto('_static/js/cookieconsent.js', 1) }}" defer></script>
89+
<script src="{{ pathto('_static/js/cookieconsent-init.js', 1) }}" defer></script>
7590
{%- endif %}
7691

7792
{%- if not embedded %}

0 commit comments

Comments
 (0)