Geographic Tracking
SFR Analytics can show which countries your visitors come from. This guide explains how country detection works and how to set it up.
How It Works
SFR Analytics does not use IP-based geolocation databases. Instead, it reads country information from HTTP headers that are added by CDNs (Content Delivery Networks) and reverse proxies. These services sit between your visitors and your server, and they add a header to each request identifying the visitor’s country.
When a pageview is tracked, the plugin checks for country headers in this order:
- Cloudflare — CF-IPCountry header
- AWS CloudFront — CloudFront-Viewer-Country header
- Generic proxy — X-Country-Code header
- Custom filter — sfran_get_country_code (for developers using other geolocation methods)
If none of these headers are present, the country is recorded as “Unknown”. All other tracking (views, visitors, sessions, referrers, devices, browsers, etc.) works normally without a CDN.
Setting Up Cloudflare (Most Common)
Cloudflare is the most popular option and is free for most websites.
If you already use Cloudflare:
Country headers are enabled by default. You do not need to change anything — SFR Analytics will automatically detect the CF-IPCountry header on every request.
To verify it is working: 1. Wait for some traffic after installing SFR Analytics 2. Go to SFR Analytics > Dashboard 3. Scroll down to the Geographic Distribution section 4. You should see country codes with flag icons and visitor counts
If you do not use Cloudflare yet:
- Create a free account at cloudflare.com
- Add your domain and follow the setup wizard to update your nameservers
- Once active (usually within a few hours), Cloudflare will automatically add the CF-IPCountry header to all requests
- No additional Cloudflare settings are needed — the country header is included by default on all plans, including the free plan
Cloudflare with a Caching Plugin
If you use a caching plugin (WP Super Cache, W3 Total Cache, LiteSpeed Cache, etc.), country detection still works because SFR Analytics tracks pageviews via a lightweight JavaScript call that bypasses page caching.
Other Supported CDNs
AWS CloudFront
If your site is served through AWS CloudFront:
- Go to your CloudFront distribution settings
- Under Cache key and origin requests, add CloudFront-Viewer-Country to the whitelist headers
- SFR Analytics will read this header automatically
Other CDNs and Proxies
Any CDN or reverse proxy that sets the X-Country-Code header with a 2-letter ISO country code will work automatically.
For Developers: Custom Geolocation
If you use a geolocation service or database (e.g. MaxMind GeoLite2) that is not based on HTTP headers, you can use the sfran_get_country_code filter:
add_filter(‘sfran_get_country_code’, function ($country_code) {
// Your custom geolocation logic here
// Must return a 2-letter ISO 3166-1 alpha-2 code (e.g. ‘GB’, ‘US’, ‘DE’)
// or null if country cannot be determined
return $country_code;
});
This filter runs after the built-in header checks, so it acts as a fallback when no CDN headers are available.
Ignoring Countries
If you want to exclude traffic from specific countries entirely (so it is not recorded at all):
- Go to SFR Analytics > Settings
- Scroll to Ignore Countries
- Enter a 2-letter country code (e.g. CN, RU, DE) and click Add
- All future traffic from that country will be ignored — visitors can still access the site, but their pageviews will not appear in analytics
This is useful for filtering out bot traffic that originates from specific countries, or for excluding your own country during testing.