Skip to content

Cookie Banner with Arcjet

Cookie banners serve as digital consent notices, informing visitors about data tracking practices. While not universally mandated, they are required in specific jurisdictions, notably the EU under GDPR. Prudent websites implement these notifications selectively, ensuring compliance where necessary while preserving a streamlined user experience in regions without such requirements.

Using Arcjet’s IP Geolocation feature it is possible to selectively show the banner’s to users resident in jurisdictions that require them, without interfering with the experience of everyone else.

Country data is available on the Free plan, but the region data is only available on the Pro and above.

const countriesRequiringCookieBanner = [
"AT",
"BE",
"BG",
"HR",
"CY",
"CZ",
"DK",
"EE",
"FI",
"FR",
"DE",
"GR",
"HU",
"IE",
"IT",
"LV",
"LT",
"LU",
"MT",
"NL",
"PL",
"PT",
"RO",
"SK",
"SI",
"ES",
"SE",
"UK",
"NO",
"IS",
"LI",
"CA",
"BR",
"MX",
"NG",
"AR",
];
const statesRequiringCookieBanner = [
"California",
"Virginia",
"Colorado",
"Connecticut",
"Utah",
"Texas",
"Oregon",
"Montana",
];
// ... imports, client configuration, etc
// See https://docs.arcjet.com/get-started
const decision = await aj.protect(req);
if (
decision.ip.hasCountry() &&
countriesRequiringCookieBanner.contains(decision.ip.country)
) {
// Show the cookie banner
}
if (
decision.ip.hasRegion() &&
statesRequiringCookieBanner.contains(decision.ip.region)
) {
// Show the cookie banner
}