Geo-IP Detection
Visitor country is resolved via a single ipapi.co call. Requests time out after 2 seconds and fall back to the strictest available profile, so a slow lookup never blocks the banner.
async function detectCountry() {
const cached = sessionStorage.getItem('sc_country');
if (cached) return cached;
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 2000);
try {
const res = await fetch('https://ipapi.co/json/', {
signal: controller.signal,
});
const { country_code } = await res.json();
sessionStorage.setItem('sc_country', country_code);
return country_code;
} catch {
return 'STRICT'; // apply most restrictive profile
} finally {
clearTimeout(timer);
}
}