Last active
May 22, 2019 07:57
-
-
Save JonathanPorta/74398227a0b4ef84043f08cd0ccad51b to your computer and use it in GitHub Desktop.
Naive check to determined if the visitor should be shown the GDPR notice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function locale(){ | |
if (navigator.languages != undefined) | |
return navigator.languages[0]; | |
else | |
return navigator.language; | |
} | |
function showGdprNotice(){ | |
const gdprCountries = [ | |
'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'EL', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'UK' | |
] | |
const l = locale(); | |
let country = null; | |
if(l.indexOf('-') > -1){ | |
// we have a locale in the form of lang-CO | |
country = l.split("-")[1]; | |
} | |
let showGdprNotice = false; | |
if(gdprCountries.indexOf(country.toUpperCase()) > -1){ | |
showGdprNotice = true; | |
} | |
return showGdprNotice; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment