Geolocation Troubleshooting

Troubleshooting – The Geolocation Condition

If you set up a geolocation trigger and it seems like it isn’t working, there are a few common points to consider.

1. Are you testing If-So on a local server or an internal environment?

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.

2. Is there a communication failure between your server and ours?

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.

3. Are you testing the site using a VPN?

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.

4. Are you using a caching plugin?

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.

5. Is it a detection accuracy issue?

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:

Report a mistake

6. Do you have enough Geolocation session credits on your account?

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.

7. Are you using Cloudflare?

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;
});

Still have a question? Feel free to contact our support team, we will be happy to help!

Related FAQs

  • The geolocation session count doesn't seem accurate

    To prevent If-So from counting a geolocation session when users browse from page to page and to optimize the website performance, If-So stores a session with the user’s location and uses the data during the user’s journey.

    A geolocation session begins when a visitor first visits a page with a geolocation trigger and ends when either the visitor closes the browser or after 25 minutes of inactivity (this might vary slightly between browsers and the server on which the website is hosted).

    My sessions count doesn’t seem to behave as described

    A problem with the session count is usually caused by one of the following:

    1. Your website (server) doesn’t store sessions
    2. Bots are visiting the site

    Troubleshooting – step-by-step

    1. On your WordPress dashboard, go to If-So > Geolocation and check your sessions count.
    2. In a new incognito window, visit a page where you use the geolocation service (a page with a trigger, Geolocation DKI shortcode, conditional Elementor or Gutenberg block, or similar).
    3. Go back to the If-So > Geolocation page, refresh the page, and check the count.
      A single geolocation session should be counted
    4. Go back to the incognito window, refresh the page, and recheck the session count.
      No session should be counted.
    5. If a session was counted, it might indicate that it wasn’t stored on your browser. Go to If-So > Settings, and check the “Disable use of PHP sessions” option.
    6. Repeat steps 1 to 4.

    If the problem wasn’t solved, there are good chances that the problem is bots visiting your website.

    1. Go to If-So > Settings and check the “Page caching compatibility” option. It might prevent or at least reduce the sessions overcount.
    2. If the problem persists, go to If-So > Settings and check the “Log geolocation requests.” Checking the option will create a log file containing all geolocation requests, including the IP and the exact time.
    3. Check the geolocation log to see if you see IPs with more than a single record appearing in a short period or ones that repeat a lot. If you find such IPs, you can enter them here and try to gather more information regarding their source. For example, if the IP points to a data center (like Google, Amazon, etc.), it could indicate that it’s a bot.

    The example below shows an IP belongs to a data center

    *Please note, enabling the geolocation log file might affect the loading speed of pages with a geolocation condition. We highly recommend disabling the log once you receive the relevant information.

    Blocking an IP

    If you decide to block a certain IP, add the code below to your function.php file, and replace the XX.XX… and YY.YYY… with the IPs you decided to block.

    add_filter('ifso_exclude_from_geo',function($exclude){ $exclude['ip'] = ['XX.XX.XXX.XXX','YY.YYY.YYY.YYY']; return $exclude; });

Ready to get started?
Try it on your website