Geolocating visitors
Up until v5.1, Shlink would always use a GeoLite2 database, by MaxMind, to geolocate visits to your short URLs.
Starting with v5.2, Shlink supports a strategy-based system to more flexibly geolocate visitors using different strategies.
Currently supported strategies are:
- GeoLite2: Geolocate visitors using a local GeoLite2 database file handled by Shlink. It requires a license key to be set.
- Cloudflare: Geolocate visitors using location headers provided by Cloudflare. It requires Shlink to be proxied by Cloudflare.
Via configuration or env vars, you can enable any number of strategies, and order them as desired. Shlink will try all enabled strategies in order until one is capable of geolocating the visitor, or all of them fail.
GeoLite2 license key
Shlink needs a GeoLite2 license key when the geolite2 strategy is enabled.
To make sure the data is always up-to-date, it downloads new versions of the database regularly.
However, in order to do this, Shlink needs a GeoLite2 license key. These licenses are free, and you can easily generate one by following the instructions below.
Warning
If you don’t provide a GeoLite2 license key, Shlink will simply not geolocate visits with the geolite2 strategy, even if explicitly enabled.
Note
If a GeoLite2 license key is provided and no geolocation strategies are explicitly set, the geolite2 strategy will be implicitly enabled.
Generate a license key
In order to generate the license key, follow these steps.
- Create a MaxMind account for GeoLite2.
- Generate a license key. Its important that you save the value, as you will not be able to recover it afterward.
Provide the license key to Shlink
Once you have your license key, you will need to provide it to Shlink.
- Via environment variable: use
GEOLITE_LICENSE_KEYto set your license key. - Via installation tool: you will be asked to provide the license key when installing or updating Shlink, or you can use set-option to set it later.