If you set up a geolocation trigger and it seems like it isn’t working, there are a few common points to consider.
Since the Geolocation condition relies on an external API to compare the user’s IP and location, the geolocation condition will only work in a live environment.
No worries, it’s not complicated to check it. On your WordPress dashboard, go to If-So > Geolocation. If the value of the “Sessions used this month” is 0/0 then it’s probably a communication failure. Please contact our support and let us know the domain of the website you are trying to use If-So on.
If-So’s Geolocation condition will not take action while browsing the site via VPN. If you don’t see the geo-targeted version, it doesn’t mean If-So is not functioning properly. Try testing the page using an online proxy server or target your own country and see if you get the correct result.
If the reason you are using a VPN is only to see how the content looks on your site, it is much easier to use the built-in testing mode option. This option allows you to preview a specific dynamic content version of your site.
Caching, in simple words, means you present your website visitors with a “snapshot” of your rendered page instead of rendering it from scratch each time a visitor enters the site.
If you’re using any kind of cache on your site (using a caching plugin, CDN, server cache, or any other), go to If-So > Settings on your WordPress dashboard and enable the Page Caching Compatibility option. Learn more about If-So’s compatibility with caching.
No IP-to-location service is 100%. The accuracy of a location depends on many factors, the most important being the ISP of the address. The accuracy is generally higher for fixed lines than it is for cellular networks.
The list below shows how If-So recognizes your location. Naturally, if you have set up a trigger and targeted your actual location while the value detected by our system is wrong, the dynamic version will not be displayed as excepted.
The good news: Accuracy issues are something we can fix. You simply need to send us your IP and your actual location and we’ll make sure the IP-to-location database we are using will be updated.
Learn more here about geolocation accuracy.
Here is what your current location appears as:
Continent:
Country:
State:
City:
Timezone:
Unlike other If-So conditions, geolocation usage is limited by monthly sessions. To see your monthly session usage, go to If-So > Geolocation on your WordPress admin. A session begins when a visitor first visits a page with a geolocation trigger and ends when the visitor closes the browser or after 25 minutes elapse.
From time to time we encounter conflicts between our geolocation service and Cloudflare. We can solve them! Paste the following code at the end of your functions.php file and try again. If it doesn’t solve the problem, please contact our support.
add_filter('ifso_user_ip',function(){
$ip = null;
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) //Cloudflare
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
elseif (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip = $_SERVER['HTTP_CLIENT_IP'];
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])[0];
else
$ip = $_SERVER['REMOTE_ADDR'];
if(!empty($ip)){
$ip = explode(':',$ip)[0];
}
return $ip;
});
Please contact our support team and provide the following information:
Country: Unknown
State: Your state
City: Unknown
Continent: Unknown
The geolocation service is powered by an IP-to-location API. When a user visits a page with a geolocation condition or DKI shortcode for the first time during their session, a request is sent to the geolocation database to compare the user’s IP with the location information stored in the database. A geolocation session starts when a visitor first accesses a page with a geolocation trigger or a Geolocation DKI shortcode and lasts until the visitor closes their browser or has been inactive for 25 minutes (note that this time frame may vary slightly depending on the browser and server hosting the website). Not every page view should count as a session! If you are experiencing issues with your session count, it is most likely due to bots visiting your site and consuming your session quota. To identify and block bots, If-So offers two options: The “Block Bots” mode allows you to automatically prevent Search Engine Crawlers, CURL Requests, and other bots from accessing the geolocation service. When the “Block Bots” mode is enabled, bots will be able to access your site as usual, but they will be blocked from accessing the geolocation service. Instead, they will be served with the default content version (or “fallback” in case you are using the Geolocation DKI shortcodes) To enable the “Block Bots” mode, follow these steps: The “Bot Blocking” mode enables you to automatically prevent Search Engine Crawlers, CURL Requests, and other bots from accessing the geolocation service. The “Bots Block” mode identifies bots by searching for commonly used terms in the User-Agent header. The following terms, if present in the User-Agent, will trigger a block: Please note that while the “Bot Blocking” mode is designed to capture the majority of bot traffic, it may not completely block all bots. Keep in mind that the User-Agent can be easily manipulated, which can potentially bypass the block. If necessary, you can utilize the “Log geolocation requests” option to manually identify IP addresses that consume your session quota excessively. By logging these requests, you can keep track of suspicious activity and take measures to manually block those IPs as needed. To exclude a specific IP from being blocked by the “Bots Block” mode, you can whitelist the IP address by adding the following shortcode at the end of your functions.php file: Please ensure to replace ‘X.X.X.X‘ and ‘Y.Y.Y.Y‘ with the respective IP addresses you wish to whitelist. If you have enabled the log file and are consistently discovering new IPs that exhaust your sessions quota by generating numerous bot sessions, please ensure that you load dynamic content using Ajax. Based on our experience, loading content with Ajax helps prevent many bots from utilizing the geo sessions. If you don’t want to automatically block search engines and other bots, If-So offers a log feature that records each geolocation request, including the IP and date and time of the request. By analyzing this log, you can pinpoint the IPs of bots that are causing the issue and block them from the geolocation service (They will still be able to visit the site, but the geolocation service will not be available for them). The example below shows an IP belongs to a data center: *Please note that enabling the geolocation log file may slow down the loading speed of pages with a geolocation condition. It is recommended to disable the log file after collecting the necessary information. If you decide to block certain IP addresses, add the following code to your function.php file, and replace the XX.XX… and YY.YYY… placeholders with the IPs you want to block.What is a geolocation session?
Troubleshooting inaccurate session counts
Block Bots mode
Which bots will be blocked?
Whitelisting IPs
add_filter('ifso_geo_whitelist',function($allow){
$allow['ip'] = ['X.XX.XX.XXX','Y.YY.YY.YYY'];
return $allow;
});
Manual blocking
Step-by-step: Blocking bots from the geolocation service
If the IP points to a data center (like Google, Amazon, etc.), it may indicate that it’s a bot.Blocking an IP Address
add_filter('ifso_exclude_from_geo',function($exclude){ $exclude['ip'] = ['XX.XX.XXX.XXX','YY.YYY.YYY.YYY']; return $exclude; });