DEAL ENDS IN:

SPRING SALE!

UP TO 35% OFF!

GET IT NOW

The geolocation session count doesn’t seem accurate

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.

What is a geolocation session?

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!

  1. The geolocation session is initiated only when a visitor accesses a page with a geolocation trigger or a geolocation DKI shortcode, and a request to the IP-to-location API is made to compare the visitor’s IP with the location in the database.
  2. If the user browses several pages within the same visit, it will still be considered a single session. The session will end when the visitor closes the browser or after 25 minutes of inactivity, though this duration may vary slightly depending on the browser and server.

Troubleshooting inaccurate session counts

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:

  1. “Block Bots” mode – automatically blocks search engines and bots that declare themselves as bots.
  2. Manual blocking – logs all geolocation requests, provides a list of IPs that extensively trigger sessions, and allows you to block them at your discretion.

Block Bots mode

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:

  1. Ensure that you have both the If-So plugin and the If-So Geolocation extension installed on your WordPress site.
  2. Access your WordPress dashboard and navigate to If-So > Settings.
  3. Under the Geolocation section, select the “Block Bots” option.

The “Bot Blocking” mode enables you to automatically prevent Search Engine Crawlers, CURL Requests, and other bots from accessing the geolocation service.

Which bots will be blocked?

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:

  • bot
  • crawl
  • slurp
  • spider
  • mediapartners
  • curl
  • wget

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.

Block Bots mode

Whitelisting IPs

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:

add_filter('ifso_geo_whitelist',function($allow){
    $allow['ip'] = ['X.XX.XX.XXX','Y.YY.YY.YYY'];
    return $allow;
});

Please ensure to replace ‘X.X.X.X‘ and ‘Y.Y.Y.Y‘ with the respective IP addresses you wish to whitelist.

Manual blocking

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).

Step-by-step: Blocking bots from the geolocation service

  1. Download and install our If-So Geolocation Extension.
  2. Go to If-So > Settings and check the “Log geolocation requests” checkbox. Checking the option will create a log file that includes the IP and the exact time of each geolocation request.
  1. Allow some time for the log file to collect data. After sufficient time has passed (depending on your website traffic), go to the If-So menu in your WordPress dashboard and click on “Analyze Geolocation Request Log”.
  2. Look for IPs with a large number of geolocation sessions. If you find such IPs, click the “More About this IP” button to gather more information about their source. If you find such IPs, click the “More About this IP” button and try to gather more information regarding their source.

    If the IP points to a data center (like Google, Amazon, etc.), it may indicate that it’s a bot.

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.

Blocking an IP Address

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.

  • The code only blocks the IPs from the geolocation functionality, and not from accessing your website.
  • Blocked IPs will see the default content version.
add_filter('ifso_exclude_from_geo',function($exclude){ $exclude['ip'] = ['XX.XX.XXX.XXX','YY.YYY.YYY.YYY']; return $exclude; });