TL;DR: Get your Banner ID from Sites → ⋮ Menu → Embed Script → Paste it and your target country codes into the snippet below → Add the snippet to your site's <head>. Your consent banner loads only for visitors from the countries you specify.

Overview

Country-based script loading conditionally loads your Consently banner only when a visitor's country matches your approved list. This is useful when your site serves a global audience, but you only need consent compliance in specific regions.

Before You Begin

Make sure you have:

  • Your Consently Banner ID — found in the Embed Script modal

  • Access to your website's <head> HTML or CMS code injection panel

Time required: 5 minutes

How to Implement Country-Based Loading

Step 1: Remove the regular Consently script

Find and delete the standard Consently embed script from your site's <head>. It looks like this:

<script src="https://app.consently.net/consently.js" data-bannerid="YOUR_BANNER_ID"></script>
⚠️ Important: The regular script and the custom snippet must not exist on the same page at the same time. Having both will cause the banner to load for all visitors, bypassing country filtering entirely.
parliamentary-elsbeth-t72b9knz.dcms.sitedashboarddesign699d70d572e74d001350 2026-02-27 at 8.39.21 PM.png

Step 2: Copy the custom snippet

Copy the script below into a text editor so you can customize it before adding it to your site:

<script>
(async function () {
try {
const allowed = ["US", "GB", "DE"]; // Replace with your target country codes
const bannerId = "YOUR_BANNER_ID"; // Replace with your Banner ID
const res = await fetch("https://ipapi.co/country/");
if (!res.ok) return;
const country = (await res.text()).trim();
if (allowed.includes(country)) {
const s = document.createElement("script");
s.src = "https://app.consently.net/consently.js";
s.async = true;
s.dataset.bannerid = bannerId;
document.head.appendChild(s);
}
} catch (e) {
console.error(e);
}
})();
</script>
BlockNote image

Step 3: Set your Banner ID

Replace YOUR_BANNER_ID in the bannerId variable with the actual Banner ID from your Consently dashboard. You can find it in the Embed Script modal.

parliamentary-elsbeth-t72b9knz.dcms.sitedashboarddesign699d70d572e74d001350 2026-02-27 at 8.46.30 PM.png

Step 4: Set your allowed countries

Replace the example codes in the allowed array with the ISO 3166-1 alpha-2 two-letter country codes for the regions you want to target.

Common codes:

Region

Code

United States

US

United Kingdom

GB

Germany

DE

France

FR

Malaysia

MY

Bangladesh

BD

Canada

CA

Australia

AU

💡 Tip: If you need GDPR compliance for EU visitors, add all relevant EU member state codes — or consider loading the banner worldwide and configuring your templates to show only to the appropriate regions. See GDPR Compliance and CCPA & US State Laws Compliance to understand which regions require consent.
parliamentary-elsbeth-t72b9knz.dcms.sitedashboarddesign699d70d572e74d001350 2026-02-27 at 8.47.37 PM.png

Step 5: Paste the snippet into your site's <head>

Add the completed snippet inside the <head> section of your HTML, in the same location where the regular script was removed.

parliamentary-elsbeth-t72b9knz.dcms.sitedashboarddesign699d70d572e74d001350 2026-02-27 at 8.49.05 PM.png

Done!

The regular script has been replaced, and the banner now loads only for visitors whose IP address resolves to one of your allowed country codes.

Success indicator: Visit your site using a VPN set to an allowed country — your consent banner should appear. Visiting from a non-allowed country should show no banner.

What's Next

Now that you've set up country-based loading, you should:

  1. Verify the banner is working correctly

  2. Review your compliance obligations by region

Troubleshooting

The banner is not appearing for any country

Why does this happen: The data-bannerid the value may be incorrect, or the snippet was not placed in the <head> section.

Solution:

  1. Double-check that YOUR_BANNER_ID was replaced with your actual Banner ID — copy it again directly from the Embed Script modal

  2. Confirm the full snippet is inside <head> and not <body>

  3. Clear your browser cache and reload the page


The banner appears for all visitors, ignoring country filtering

Why this happens: You may have another copy of the standard Consently embed script installed separately on the same page.

Solution:

  1. Search your site's <head> code for any existing app.consently.net/consently.js script tags

  2. Remove any duplicate standard embed scripts — the country-based snippet should be the only Consently script present


The banner is not appearing, even with a VPN set to an allowed country

Why this happens: Some VPN exit nodes use IP ranges not recognized by ipapi.co, or the ipapi.co The service may be temporarily unreachable.

Solution:

  1. Test with a different VPN server in the same country

  2. Open your browser console and check for any network errors on the ipapi.co/country/ request

  3. If ipapi.co is blocked in your environment, consult your developer to substitute an alternative IP geolocation API

Related Pages