Skip to content

Commit cda94bb

Browse files
committed
fix cookies banner
1 parent eed3d94 commit cda94bb

File tree

10 files changed

+88
-26
lines changed

10 files changed

+88
-26
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ layout: page
33
title: CHANGELOG
44
---
55

6+
## v7.4.1
7+
Nov 27 2017
8+
{:.heading.post-date}
9+
10+
### Fixed
11+
* Fixed storing user-related data before accepting cookies.
12+
* Fixed tab order of cookie banner, so keyboard users can access it more easily.
13+
* Accepting cookies no longer causes a page reload in some browsers.
14+
* Fixed appearance of the okay button in the free version.
15+
* Menu icon now useable while the cookies banner is active.
16+
* Loading icon is now visible while the cookies banner is active.
17+
* Removed cookies banner from print layout.
18+
* Removed inline styles from cookie banner.
19+
620
## v7.4.0
721
Nov 25 2017
822
{:.heading.post-date}

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ hydejack:
134134
# Set to `true` when building with the `--lsi` option
135135
use_lsi: false
136136

137-
# Set to `true` if you want to display a cookie notice banner.
138-
# You can change the text of the banner in `_data/strings.yml`.
137+
# When using Google Analytics, set to `true` to display a cookie notice banner.
138+
# When enabled, no user-related data will be stored until the user gives consent.
139139
cookies_banner: false
140140

141141

_includes/body/scripts.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
{% unless page.redirect %}
22
{% if site.google_analytics %}
3-
<script>
4-
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
5-
ga('create', '{{ site.google_analytics }}', 'auto');
6-
ga('send', 'pageview');
7-
loadJSDeferred('https://www.google-analytics.com/analytics.js');
8-
</script>
3+
<script>
4+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
5+
{% if site.hydejack.cookies_banner %}
6+
if (navigator.CookiesOK) {
7+
ga('create', '{{ site.google_analytics }}', 'auto');
8+
} else if (localStorage && localStorage.getItem('hy:cookiesOK')) {
9+
ga('create', '{{ site.google_analytics }}', {
10+
'storage': 'none',
11+
'clientId': localStorage.getItem('ga:clientId')
12+
});
13+
} else {
14+
ga('create', '{{ site.google_analytics }}', {
15+
'storage': 'none'
16+
});
17+
ga('set', 'forceSSL', true);
18+
ga('set', 'anonymizeIp', true);
19+
}
20+
{% else %}
21+
ga('create', '{{ site.google_analytics }}', 'auto');
22+
{% endif %}
23+
ga('send', 'pageview');
24+
loadJSDeferred('https://www.google-analytics.com/analytics.js');
25+
</script>
926
{% endif %}
1027

1128
<!--[if gt IE 9]><!---->
1229
{% capture js_url %}{% link assets/js/hydejack-7.4.0.js %}{% endcapture %}
1330
<script>loadJSDeferred('{{ js_url | relative_url }}');</script>
14-
1531
{% include my-scripts.html %}
16-
1732
<!--<![endif]-->
1833
{% endunless %}

_includes/styles/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
font-family: {{ font | default:"serif" }};
8989
}
9090

91-
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .heading {
91+
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .heading {
9292
font-family: {{ font_heading | default:"serif" }};
9393
}
9494
{% endunless %}

_includes/templates.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ <h1 class="page-title">{{ strings.error.title | default:"Error" }}</h1>
3535
</a>
3636
</template>
3737

38-
{% if site.hydejack.cookies_banner %}
38+
{% if site.google_analytics and site.hydejack.cookies_banner %}
3939
<template id="_cookies-banner-template">
4040
<div id="_cookies-banner" class="navbar fixed-top CookiesOK">
4141
<div class="content">
42-
<div class="nav-btn-bar" style="background: rgba(255,255,255,0.9);">
43-
<small class="nav-btn" style="padding: .875rem;">
42+
<div class="nav-btn-bar">
43+
<small class="nav-btn">
4444
<span>{{ site.data.strings.cookies_banner.text | default:'This site uses Cookies.' | markdownify | replace:'<p>','' | replace:'</p>','' }}</span>
45-
<a href="#" id="_cookies-ok" class="btn btn-primary btn-sm">{{ site.data.strings.cookies_banner.okay | default:'Okay' }}</a>
45+
<button id="_cookies-ok" class="btn btn-primary btn-sm">{{ site.data.strings.cookies_banner.okay | default:'Okay' }}</button>
4646
</small>
4747
</div>
4848
</div>

_js/src/cookies-banner.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
if (!navigator.CookiesOK && !(localStorage && localStorage.getItem('cookies-ok'))) {
17+
if (window.ga && !navigator.CookiesOK && !(localStorage && localStorage.getItem('hy:cookiesOK'))) {
1818
const template = document.getElementById('_cookies-banner-template');
1919
if (template) {
20-
document.getElementsByTagName('hy-push-state')[0]
21-
.appendChild(document.importNode(template.content, true));
20+
const parent = document.getElementsByTagName('hy-push-state')[0];
21+
parent.insertBefore(document.importNode(template.content, true), parent.firstChild);
2222

23-
document.getElementById('_cookies-ok').addEventListener('click', (e) => {
24-
e.preventDefault();
25-
if (localStorage) localStorage.setItem('cookies-ok', true);
26-
const cookiesBanner = document.getElementById('_cookies-banner');
27-
cookiesBanner.parentNode.removeChild(cookiesBanner);
23+
document.getElementById('_cookies-ok').addEventListener('click', () => {
24+
if (localStorage) localStorage.setItem('hy:cookiesOK', true);
25+
26+
const banner = document.getElementById('_cookies-banner');
27+
banner.parentNode.removeChild(banner);
28+
29+
window.ga((tracker) => {
30+
window.ga('set', 'anonymizeIp', undefined);
31+
if (localStorage) localStorage.setItem('ga:clientId', tracker.get('clientId'));
32+
});
2833
}, { once: true });
2934
}
3035
}

_js/src/push-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const DURATION = 250;
9393
const FADE_DURATION = 600;
9494

9595
// Time a user has to stay on the site before we send word to Google Analytics.
96-
const GA_DELAY = 1000;
96+
const GA_DELAY = 500;
9797

9898
// Details of the fade-out animation.
9999
const FADE_OUT = [

_sass/hydejack/__inline/_menu.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@
6363
}
6464
// @media print { display: none; }
6565
}
66+
67+

_sass/hydejack/__link/_menu.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
position: absolute;
3939
top: 0;
4040
right: 0;
41-
padding: 1.75rem 1.5rem;
41+
padding: 1.75rem 1rem;
4242
}
4343

4444

@@ -50,3 +50,16 @@
5050
}
5151
@media print { display: none; }
5252
}
53+
54+
55+
#_cookies-banner {
56+
.nav-btn { padding: 1.75rem 0 }
57+
.nav-btn-bar {
58+
margin: 0 2rem;
59+
@media screen and (min-width: $break-point-3) {
60+
margin: 0 2rem 0 0;
61+
}
62+
}
63+
@media print { display: none; }
64+
}
65+

_sass/hydejack/_menu.pre.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
position: absolute;
5555
top: 0;
5656
right: 0;
57-
padding: 1.75rem 1.5rem;
57+
padding: 1.75rem 1rem;
5858
}
5959
// >>>>
6060

@@ -66,3 +66,16 @@
6666
}
6767
@media print { display: none; } // link
6868
}
69+
70+
// <<<< LINK
71+
#_cookies-banner {
72+
.nav-btn { padding: 1.75rem 0 }
73+
.nav-btn-bar {
74+
margin: 0 2rem;
75+
@media screen and (min-width: $break-point-3) {
76+
margin: 0 2rem 0 0;
77+
}
78+
}
79+
@media print { display: none; }
80+
}
81+
// >>>>

0 commit comments

Comments
 (0)