Thinking about switching to GeoIP2 for better location detection? Here’s what you should know

In Matomo 3.5.0 we added a new feature to improve the location detection (country, region, city) of your visitors. Especially when it comes to IPv6 addresses, you will see less “Unknown” locations and more accurate results in general. This feature is now enabled for all new installations but needs to be manually enabled for existing Matomo self-hosted users.

Why is the Matomo plugin not enabled for existing users?

When you enable the GeoIP2 plugin, a database update will need to be executed on two datatable tables (“log_visit” and “log_conversion”) which stores some of the raw data. Please be aware that this update could take several hours depending on the size of your database.

If you store many visits in your database, it is recommended to execute the update through the command line by executing the command ./console core:update to avoid the update from timing out. You may also have to put your Matomo into maintenance mode during this time and replay the missed traffic from logs afterwards as explained in the FAQ article.

GeoIP2 may slow down your tracking

In the past we have seen that a few Matomo databases with high traffic volumes struggle to handle all the tracking requests after enabling GeoIP2. The reason for this is the location database now contains many more entries because it has to store all the IPv6 addresses and the database itself has a different format. Hence, the location lookup takes longer.

It is hard to say how much slower the location lookup gets, but we found GeoIP2-PHP is about 20 times slower than GeoIP1-PHP. On a fast CPU the lookup time for an IP with GeoIP2 takes about 1ms, but can also take much longer depending on the server.

Making location lookups fast again

There is a PHP extension available that makes lookups very fast, even faster than the old GeoIP1-PHP provider. If you can install additional PHP extensions on your server and have a high traffic website, you may want to install the GeoIP2 extension.

There is also an Nginx module and an Apache module. Unfortunately, we don’t have any performance metrics for these providers.

How do I activate the GeoIP2 location provider?

As a Super User, log in to your Matomo and go to “Administration => Plugins”. There you can activate the “GeoIP2” plugin. As mentioned, this will trigger a database update which can take a while and you may want to perform this update through the command line.

Now you can go to “Administration => Geolocation”. Here you will first need to install the GeoIP2 databases at the bottom of the page before you can activate the GeoIP2-PHP provider. To activate any of the other GeoIP2 providers, you will need to install the required modules.

You will be able to check if the detection works on the right next to location provider. Once you selected one of the available providers, you’re all good to go.

Share this post