Skip to content

Commit 311323a

Browse files
committed
Display cookies banner for EU users only
1 parent 5c13290 commit 311323a

File tree

3 files changed

+84
-25
lines changed

3 files changed

+84
-25
lines changed

App/containers/App.js

+78-25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
33
import {Adsense} from '@ctrl/react-adsense';
44
import { ConsentProvider, ConsentBanner } from 'react-hook-consent';
55
import 'react-hook-consent/dist/styles/style.css';
6+
const dayjs = require('dayjs')
7+
const timezone = require('dayjs/plugin/timezone')
68

79
import {connect} from 'react-redux';
810

@@ -13,10 +15,47 @@ import * as actions from '../actions';
1315
import CodeContainer from './CodeContainer';
1416
import OptionsContainer from './OptionsContainer';
1517

18+
const EU_TIMEZONES = [
19+
'Europe/Vienna',
20+
'Europe/Brussels',
21+
'Europe/Sofia',
22+
'Europe/Zagreb',
23+
'Asia/Famagusta',
24+
'Asia/Nicosia',
25+
'Europe/Prague',
26+
'Europe/Copenhagen',
27+
'Europe/Tallinn',
28+
'Europe/Helsinki',
29+
'Europe/Paris',
30+
'Europe/Berlin',
31+
'Europe/Busingen',
32+
'Europe/Athens',
33+
'Europe/Budapest',
34+
'Europe/Dublin',
35+
'Europe/Rome',
36+
'Europe/Riga',
37+
'Europe/Vilnius',
38+
'Europe/Luxembourg',
39+
'Europe/Malta',
40+
'Europe/Amsterdam',
41+
'Europe/Warsaw',
42+
'Atlantic/Azores',
43+
'Atlantic/Madeira',
44+
'Europe/Lisbon',
45+
'Europe/Bucharest',
46+
'Europe/Bratislava',
47+
'Europe/Ljubljana',
48+
'Africa/Ceuta',
49+
'Atlantic/Canary',
50+
'Europe/Madrid',
51+
'Europe/Stockholm'
52+
];
53+
1654
class App extends Component {
1755

1856
state = {
19-
cookiesEnabled: false
57+
cookiesEnabled: false,
58+
consentRequired: this.isConsentRequired()
2059
}
2160

2261
static propTypes = {
@@ -37,6 +76,12 @@ class App extends Component {
3776
window.enableCookies = this.enableCookies.bind(this);
3877
}
3978

79+
componentDidMount() {
80+
if (!this.state.consentRequired) {
81+
this.enableCookies()
82+
}
83+
}
84+
4085
obfuscate() {
4186
const {dispatch} = this.props;
4287
const {code, options} = this.props;
@@ -64,6 +109,12 @@ class App extends Component {
64109
downloadFile(data);
65110
}
66111

112+
isConsentRequired() {
113+
dayjs.extend(timezone);
114+
115+
return EU_TIMEZONES.includes(dayjs.tz.guess());
116+
}
117+
67118
enableCookies() {
68119
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0;
69120
}
@@ -109,30 +160,32 @@ class App extends Component {
109160

110161
<OptionsContainer/>
111162

112-
<ConsentProvider
113-
options={{
114-
services: [
115-
{
116-
id: 'analytics_and_ads',
117-
name: 'Analytics & Ads',
118-
scripts: [
119-
{ id: 'enable-cookies', code: 'window.enableCookies()' },
120-
],
121-
cookies: [],
122-
mandatory: false,
123-
},
124-
],
125-
theme: 'light',
126-
}}
127-
>
128-
<ConsentBanner
129-
settings={{ hidden: false, label: 'More', modal: { title: 'Cookie settings' } }}
130-
decline={{ hidden: true }}
131-
approve={{ label: 'Accept' }}
132-
>
133-
obfuscator.io uses cookies according to the <a href="/docs/cookie-policy.docx">cookie policy</a>
134-
</ConsentBanner>
135-
</ConsentProvider>
163+
{this.state.consentRequired && (
164+
<ConsentProvider
165+
options={{
166+
services: [
167+
{
168+
id: 'analytics_and_ads',
169+
name: 'Analytics & Ads',
170+
scripts: [
171+
{ id: 'enable-cookies', code: 'window.enableCookies()' },
172+
],
173+
cookies: [],
174+
mandatory: false,
175+
},
176+
],
177+
theme: 'light',
178+
}}
179+
>
180+
<ConsentBanner
181+
settings={{ hidden: false, label: 'More', modal: { title: 'Cookie settings' } }}
182+
decline={{ hidden: true }}
183+
approve={{ label: 'Accept' }}
184+
>
185+
obfuscator.io uses cookies according to the <a href="/docs/cookie-policy.docx">cookie policy</a>
186+
</ConsentBanner>
187+
</ConsentProvider>
188+
)}
136189
</React.Fragment>
137190
);
138191
}

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"classnames": "2.2.6",
3333
"codemirror": "5.59.2",
3434
"css-loader": "5.0.1",
35+
"dayjs": "1.11.9",
3536
"emoji-dictionary": "^1.0.11",
3637
"eslint": "7.18.0",
3738
"eslint-plugin-react": "7.22.0",

0 commit comments

Comments
 (0)