Skip to content

Instantly share code, notes, and snippets.

@JonathanPorta
Last active May 22, 2019 07:57
Show Gist options
  • Save JonathanPorta/74398227a0b4ef84043f08cd0ccad51b to your computer and use it in GitHub Desktop.
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.
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