Geolocation
Last updated
Was this helpful?
This guide explains how to detect a user’s country and decide when AgeGO should be triggered based on geographic and regulatory requirements.
The solution supports:
One country
Multiple countries
A clear fallback logic when detection fails
AgeGO can be triggered only for users coming from specific countries, while users from other countries can access the content directly.
This setup allows you to:
Enforce age verification only where legally required
Reduce friction in countries where age verification is not mandatory
Use a single implementation for multiple geographies
You define:
Which country or countries require AgeGO
Which AgeGO asi should be used for your domain
Before implementing this logic, make sure you have:
An active AgeGO account
Your AgeGO asi (alpha-numeric)
A country detection method, such as:
Server-side geolocation
Client-side IP-based country detection
A CMP or analytics tool providing country code
Country codes must follow ISO 3166-1 alpha-2 format, for example:
IT (Italy)
FR (France)
ES (Spain)
DE (Germany)
Hide content of the web page:
Wrap all content that should be gated by logic inside #general and keep it hidden initially.
Redirect users with disabled JavaScript.
If you do not already have a country detection solution, we recommend using the following priority:
IP-based geolocation via geojs.io (primary)
IP-based geolocation via ipapi.co (fallback)
Browser language (last fallback only)
The first valid country code detected should be used.
Note: Browser language is less reliable and should only be used when IP-based methods are not available.
asiThe asi is an alpha-numeric identifier provided by AgeGO
It identifies your domain and configuration
It is not related to the country
Note:
✔ The same site ID can be used for one or multiple countries.
❌ Country code and site ID are not the same thing.
You can simulate different countries during testing in Google Chrome DevTools - Console.
Simulate an enforced country
Simulate a non-enforced country
Reset the browser's memory
Always use ISO country codes
Keep country enforcement configurable, not hardcoded
Use comma-separated values for scalability
Make sure the same site ID is used consistently per domain
Country detection should happen before loading AgeGO
AgeGO can be conditionally enforced by country
One or multiple countries are supported
Configuration is simple and scalable
The same logic works for all markets
This approach allows you to remain compliant while maintaining the best possible user experience.
Last updated
Was this helpful?
Was this helpful?
<div id="general" style="display:none;"><div id="general" style="display:none;"> //hides content
<section class="section bg-light">
<div class="container">
<h2>Ad Section</h2>
<p class="small">Banner</p>
<script async type="application/javascript" src="https://test.example.com/ad-provider.js"></script>
<ins class="eas6a97888e2" data-zoneid="5759198"></ins>
<script>(AdProvider = window.AdProvider || []).push({ "serve": {} });</script>
</div><!-- ...existing code... -->
<noscript>
<meta http-equiv="refresh" content="0; url=https://myapi.agego.com/noJS" />
</noscript>
<!-- ...existing code... --><script>
async function loadCountryLogic() {
let countryCode = localStorage.getItem('userCountry');
if (!countryCode) {
try {
const res = await fetch('https://get.geojs.io/v1/ip/country.json');
const data = await res.json();
countryCode = data.country || 'unknown';
localStorage.setItem('userCountry', countryCode);
} catch (err) {
console.warn('GeoJS API failed, trying fallback...');
try {
const res2 = await fetch('https://ipapi.co/json/');
const data2 = await res2.json();
countryCode = data2.country_code || 'unknown';
localStorage.setItem('userCountry', countryCode);
} catch (err2) {
console.warn('All geo APIs failed, using browser language.');
const lang = navigator.language || navigator.userLanguage;
countryCode = (lang && lang.includes('-')) ? lang.split('-')[1] : 'unknown';
}
}
}
console.log('Detected country:', countryCode);
if (countryCode === 'IT') {
// Example for multiple countries:
const targetCountries = ['IT', 'FR', 'DE', 'ES', 'GB'];
if (targetCountries.includes(countryCode)) {
runAgeGoVerification(countryCode);
} else {
showAdsDirectly(countryCode);
}
function runAgeGoVerification(countryCode) {
const general = document.getElementById('general');
if (general) general.style.display = 'block';
const script = document.createElement('script');
script.src = "https://verifycdn.agego.com/v2/verify.js";
script.onload = function () {
window.AGEGO = window.AGEGO || function () { (AGEGO.e = AGEGO.e || []).push(arguments) };
AGEGO('init', {
asi: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // replace with your AgeGO asi
autoBlur: true,
verifyMode: 'inline',
requireAgeVerification: true,
allowDirectContinue: false,
underageRedirectTo: 'https://google.com',
overlay: {
logo: '', // Add a link to your logo image to be shown in AgeGO widget
theme: 'auto'
}
});
AGEGO('launch');
};
document.head.appendChild(script);
}
function showAdsDirectly(countryCode) {
const general = document.getElementById('general');
if (general) general.style.display = 'block';
}
}
}
loadCountryLogic();
</script>localStorage.setItem('userCountry', 'IT');location.reload();localStorage.setItem('userCountry', 'US');location.reload();localStorage.clear();location.reload();