Geolocation Not Working

DigiConsent Pro includes geolocation features that allow you to show different consent banners or requirements based on visitor location. This is particularly useful for GDPR compliance, where stricter consent requirements apply to visitors from the European Union while visitors from other regions might see simplified banners or no banner at all. When geolocation isn’t working correctly, all visitors see the same banner regardless of location, or the wrong banner appears for certain regions. This guide helps you troubleshoot and resolve geolocation issues.

Geolocation relies on determining visitor location through their IP address. This involves either querying external geolocation databases, using server-side geolocation services, or leveraging CDN geolocation features. Multiple points of failure can prevent accurate location detection, and understanding how your specific geolocation implementation works is essential for troubleshooting.

How Geolocation Detection Works

Geolocation for cookie consent typically works by looking up the visitor’s IP address in a database that maps IP ranges to geographic locations. This happens server-side before the page is fully generated, or client-side through JavaScript API calls to geolocation services.

Server-side geolocation: When a visitor requests your page, your server captures their IP address, queries a geolocation database or service to determine their country or region, and then outputs the appropriate banner configuration for that location. This approach is reliable and works even if JavaScript is disabled, but it requires proper server configuration and database access.

Client-side geolocation: The page loads with JavaScript that sends the visitor’s IP address to a geolocation API, receives location data, and then displays the appropriate banner. This is easier to implement but slower (requires an additional API request) and fails if JavaScript is blocked or the API is unavailable.

CDN-based geolocation: If you use a CDN like Cloudflare, it can detect visitor location and add headers to requests containing country codes. Your server or DigiConsent can read these headers to determine location. This is fast and reliable but requires CDN configuration.

Understanding which method DigiConsent uses in your setup helps you troubleshoot. Check the plugin documentation or settings to identify your geolocation method.

Geolocation Database Issues

If DigiConsent uses a local geolocation database (like MaxMind’s GeoLite2 or GeoIP), the database must be installed, readable, and up-to-date for accurate location detection.

Database not installed: Some geolocation implementations require you to download and install a database file separately. MaxMind’s databases, for example, require registration and manual download. If the database file is missing, geolocation cannot work.

Check DigiConsent’s settings or system status page for geolocation database information. It should indicate whether a database is installed, where it’s located, and when it was last updated. If it shows no database installed or an error accessing the database, that’s your problem.

Solution: Download the required geolocation database according to DigiConsent’s documentation. For MaxMind databases, you need to create a free account on their website, generate a license key, and download the GeoLite2 Country database. Upload this database to the location specified in DigiConsent settings, typically somewhere in your WordPress wp-content directory.

File permissions preventing access: Even if the database file is uploaded, incorrect file permissions can prevent WordPress from reading it. The file needs to be readable by the web server user (typically www-data on Linux servers).

Access your server via FTP or SSH and check file permissions on the geolocation database file. It should have permissions of 644 (readable by everyone, writable only by owner). If permissions are too restrictive (like 600), WordPress cannot read the file.

Solution: Change file permissions to 644 using your FTP client or command line. In command line:

chmod 644 /path/to/geolocation/database.mmdb

Outdated database: IP address assignments change constantly as internet service providers acquire new IP ranges or reassign existing ones. Geolocation databases become less accurate over time if not updated. An outdated database might misidentify visitor locations, showing EU banners to non-EU visitors or vice versa.

MaxMind updates GeoLite2 databases weekly. If your database is months or years old, it will have accuracy issues. Check the database file’s modification date or the last updated timestamp in DigiConsent settings.

Solution: Download the latest version of the geolocation database and replace your old file. Consider automating database updates if DigiConsent supports it, or set a calendar reminder to manually update the database monthly.

API-Based Geolocation Problems

If DigiConsent uses an external API for geolocation (services like ip-api.com, ipinfo.io, or MaxMind’s web service), API connectivity problems can prevent location detection.

API key issues: Most geolocation APIs require an API key for authentication. If the key is missing, invalid, or exceeded its usage limits, API requests fail and geolocation doesn’t work.

Check DigiConsent settings for API key configuration. Verify you’ve entered the key correctly—API keys are long strings that must be copied exactly without extra spaces or characters. Test the API key by making a manual request (some API services provide testing tools in their dashboards).

Solution: If the API key is invalid, generate a new one through your geolocation service account and update it in DigiConsent settings. If you’ve exceeded usage limits (free tiers often limit requests to a certain number per day or month), consider upgrading to a paid plan or switching to a database-based approach that doesn’t require API calls for every visitor.

Rate limiting: Even with a valid API key, you might hit rate limits if your site has high traffic. When rate limits are exceeded, the API refuses additional requests until the limit resets, causing geolocation to fail for those visitors.

Check your geolocation service dashboard for usage statistics. If you’re consistently hitting limits, you need a higher tier or a different approach.

Solution: Implement caching of geolocation results. Instead of checking location for every single page view, cache the visitor’s location in a cookie or session for a period of time (like 24 hours). This dramatically reduces API calls—you only check location once per visitor per day rather than on every page load. DigiConsent might include this caching automatically; verify in settings or documentation.

Network connectivity issues: If your server cannot reach the external geolocation API due to firewall restrictions, DNS problems, or network issues, API requests fail silently and location cannot be determined.

Testing API connectivity: SSH into your server and test connectivity to the geolocation API:

curl https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY

Replace the URL with your actual API endpoint. If the request times out or returns connection errors, your server cannot reach the API. This might be due to firewall rules blocking outbound connections or DNS issues preventing domain resolution.

Solution: Contact your hosting provider and request that they allow outbound connections to your geolocation API’s domain and IP addresses. Provide them with the specific domains that need to be whitelisted. Most quality hosting providers allow outbound connections by default, but some managed WordPress hosts or security-hardened servers restrict them.

CDN and Proxy Issues

CDNs and reverse proxies sit between visitors and your server, which complicates IP address detection. Your server sees the CDN’s IP address instead of the visitor’s real IP, causing geolocation to detect the CDN’s location rather than the visitor’s.

Cloudflare and real IP detection: When using Cloudflare (or similar CDNs), all requests to your server come from Cloudflare’s IP addresses. The visitor’s actual IP is passed in HTTP headers like CF-Connecting-IP (Cloudflare) or X-Forwarded-For (standard proxy header).

DigiConsent must be configured to read the visitor’s IP from these headers rather than from the direct connection. If it’s reading the connection IP, it will geolocate Cloudflare’s servers (typically showing as US locations) instead of your visitors.

Solution: Verify DigiConsent is configured to use the correct IP header. Check settings for options related to “Trust proxy headers,” “Read real IP,” or similar. Enable the option to read IP from headers like X-Forwarded-For or CF-Connecting-IP.

If DigiConsent doesn’t have this setting, you may need to configure WordPress itself to properly detect visitor IPs behind proxies. This can be done with code in wp-config.php:

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}

This makes WordPress (and plugins) see the visitor’s real IP instead of the proxy IP. However, only enable this if you’re actually behind a trusted proxy like Cloudflare—enabling it without a proxy creates a security vulnerability where visitors can spoof their IP addresses.

Cloudflare’s built-in geolocation: Cloudflare includes geolocation data in the CF-IPCountry header, which contains a two-letter country code. This is extremely fast and reliable because Cloudflare has already determined location—you just read the header without any database lookups or API calls.

If DigiConsent supports reading location from Cloudflare headers directly, this is the ideal solution. Configure DigiConsent to use CF-IPCountry for location detection. This only works if Cloudflare is your CDN and you have the feature enabled (available on all Cloudflare plans including free).

Caching Preventing Geolocation

Aggressive caching can completely break geolocation functionality. If your site serves the same cached page to all visitors regardless of location, everyone sees the same banner. A visitor from Germany and a visitor from the US would both see whichever version of the page was cached first.

Page caching without variations: Standard page caching creates one cached version of each page. When geolocation is involved, you need cache variations—different cached versions for different locations. Without this, the first visitor’s location determines what banner all subsequent visitors see.

Testing for cache issues: Use a VPN or proxy to visit your site from different countries. If you see the same banner regardless of which country you appear to be from, caching is likely serving the same page to everyone.

Alternatively, test by comparing what you see (from your actual location) to what Cloudflare or another CDN preview shows for different regions. If they’re identical when they should differ, caching is the issue.

Solution – Implement cache variations: Configure your caching plugin or CDN to create separate cache entries based on visitor location. In advanced caching plugins like WP Rocket or LiteSpeed Cache, look for settings like “Cache Vary” or “Separate cache by cookie/location.”

For Cloudflare, you can use Cache Rules (previously Page Rules) to vary cache by country. Create a rule that includes Vary: CF-IPCountry in cache keys, ensuring different countries get different cached versions.

Solution – Use client-side geolocation: An alternative to cache variations is handling geolocation entirely client-side. Cache the page normally but load it with JavaScript that determines location and shows the appropriate banner. This is slower (requires JavaScript execution and possibly an API call) but works with standard caching.

The cached HTML includes the banner code for all regions, but JavaScript detects location and shows only the relevant banner. This increases initial page size (loading all banner variations) but avoids cache complexity.

Testing and Verifying Geolocation

Proper testing requires viewing your site from different geographic locations, which is challenging if you’re physically in one location. Several methods allow testing geolocation without traveling.

VPN testing: VPN services allow you to route your traffic through servers in different countries, making your site see you as coming from those locations. Subscribe to a VPN service with servers in the regions you need to test (typically EU countries for GDPR testing and non-EU countries for comparison).

Connect to a VPN server in Germany, clear your browser cookies and cache, and visit your site. You should see the EU version of the banner. Disconnect and connect to a US server, clear cookies/cache again, and visit—you should see the non-EU version (or no banner if that’s your configuration).

Proxy services: Web-based proxy services route your browsing through different countries without installing VPN software. Services like Hide.me or ProxySite offer free options with servers in various countries. These work for basic testing though they’re not as reliable as VPNs.

Browser extensions: Some VPN providers offer browser extensions that are simpler than full VPN clients. These route only browser traffic through different locations, making testing quick and easy.

IP geolocation testing tools: Before testing on your actual site, verify that geolocation is detecting your VPN/proxy location correctly. Visit a geolocation testing site like whatismyipaddress.com or ipinfo.io while connected to your VPN. Confirm it shows the expected country. If the testing tool shows you’re in Germany but your site still shows the wrong banner, the problem is with DigiConsent’s configuration, not with the VPN.

DigiConsent testing mode: Some consent management plugins include testing modes where you can manually select a location to simulate, bypassing actual geolocation detection. Check DigiConsent settings for development or testing options that let you preview different geographic versions without VPNs. This is ideal for development but remember to disable testing mode on your live site.

Regional Configuration Mistakes

Sometimes geolocation works perfectly, but your regional configuration is incorrect, causing unexpected banner behavior.

Incorrect country codes: When configuring which countries see which banner, you typically specify countries using two-letter ISO codes (DE for Germany, FR for France, US for United States, etc.). Using incorrect codes means countries won’t match properly.

Double-check that you’re using correct ISO 3166-1 alpha-2 country codes. A common mistake is using three-letter codes or full country names instead of the two-letter standard. DigiConsent should specify which format it expects in the settings interface.

EU membership changes: The list of European Union member countries changes occasionally as countries join or leave. If your configuration specifies individual EU countries rather than using an “EU” group designation, you might miss newly joined countries or incorrectly include countries that have left.

Solution: If DigiConsent offers an “EU” or “EEA” (European Economic Area) option, use that instead of listing individual countries. This automatically includes all current member states and updates as membership changes. If you must list countries individually, verify your list against the current official EU membership.

Conflicting rules: If you’ve created multiple geolocation rules that overlap or conflict, unexpected behavior results. For example, one rule might say “Show banner A to EU visitors” while another says “Show banner B to German visitors.” Germany is in the EU, so which rule applies?

Review all your geolocation rules and ensure they’re structured logically without conflicts. Organize rules from most specific to least specific, and verify DigiConsent’s documentation on rule precedence—does the first matching rule apply, or the most specific, or the last defined?

Localhost and Development Environment Issues

Geolocation typically doesn’t work on localhost or local development environments because your computer doesn’t have a public IP address that geolocation databases can identify.

When accessing your site via localhost or 127.0.0.1, geolocation sees a local IP address and cannot determine a real geographic location. Some geolocation services return errors, others default to a specific country (often US), and some return no location at all.

Solution for development testing: Use DigiConsent’s testing mode (if available) to manually set your location for testing purposes. Alternatively, use a staging site that’s publicly accessible with a real IP address rather than testing on localhost.

If you must test on localhost, configure your geolocation to treat unknown/local IPs as a specific country so you can at least test one regional configuration. Just remember this is artificial and you must still test with real IP addresses before going live.

Privacy Networks and Anonymization

Users on privacy networks like Tor, VPNs, or Apple’s iCloud Private Relay have IP addresses that might not accurately reflect their real location. Tor users might appear to be from wherever their exit node is located. VPN users appear to be from the VPN server location. iCloud Private Relay obfuscates location to a broad region.

This isn’t something you can “fix” because these users are intentionally hiding their location. Your geolocation will show their apparent location (where their traffic exits), not their real location. For GDPR compliance, this generally means showing the most restrictive banner (the EU version) to any visitor whose location cannot be determined with certainty, erring on the side of caution.

Consider configuring a default behavior for when location cannot be determined: either show the most restrictive banner to ensure compliance, or show a neutral banner asking users to confirm their region. Document this decision in your privacy policy.

Diagnostic Checklist

When troubleshooting geolocation issues, work through this systematic checklist:

  1. Verify geolocation is enabled in DigiConsent settings
  2. Check which geolocation method is being used (database, API, CDN headers)
  3. If using a database, verify it’s installed, readable, and recent
  4. If using an API, verify the API key is valid and not rate-limited
  5. Test API connectivity from your server with curl or similar tools
  6. If behind a CDN/proxy, verify real IP detection is configured correctly
  7. Review cache configuration and ensure it varies by location or geolocation is client-side
  8. Verify regional rules use correct country codes and have no conflicts
  9. Test with a VPN from different countries to confirm different banners appear
  10. Check browser console and server error logs for geolocation-related errors
  11. Confirm you’re testing on a publicly accessible site, not localhost
  12. Verify plugin version is current with latest geolocation improvements

Geolocation adds valuable functionality for managing regional compliance requirements, but it introduces complexity that requires proper configuration and testing. By understanding how geolocation works in your specific setup and methodically troubleshooting issues, you can ensure visitors from different regions receive the appropriate consent banners for their jurisdictions.