Making the Geolocation Database Download Work in a Private Network

WP Statistics downloads the Geolocation database from JSDelivr by default and hosts it locally in wp-content/uploads/wp-statistics. However, since the private network or intranet does not have access to JSDelivr for downloading the database, this document provides instructions on how to ensure WP Statistics uses a locally hosted Geolocation database while maintaining compatibility with a private network.

Filter: wp_statistics_geolocation_download_url

The wp_statistics_geolocation_download_url filter allows customization of the URL used to download the Geolocation database in the WP Statistics. This is particularly useful when hosting the Geolocation database on a private network or custom server.

Downloading and Hosting the Geolocation Database

  1. Host the Geolocation Database:
    • Download the Geolocation database from DB-IP or MaxMind.
    • Upload and host the database file to a directory on your private network server.
  2. Customize the Download URL:
    • Use the wp_statistics_geolocation_download_url filter to override the default download URL with the URL of your hosted Geolocation database.
    • Add the following code to your theme’s functions.php file or a custom plugin:
function custom_geoip_download_url($defaultUrl) {
    // Change the URL to your custom GeoIP database URL hosted on your private network
    $customUrl = 'https://your-private-network-server.com/path-to-geoip-database/geoip-database.tar.gz';
    return $customUrl;
}
add_filter('wp_statistics_geolocation_download_url', 'custom_geoip_download_url');

By following these steps, you can successfully ensure WP Statistics uses a locally hosted Geolocation database while maintaining compatibility with your private network.

Let’s get started
Take your business to next level

Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.