What is Geolocation?

Geolocation is the identification of the geographical location of a device in the real world, for example, the computer connected to the internet with which you are reading this article; the most advanced version is based on GPS, but it requires that the device is equipped with such technology and that the sharing of this data is activated by the device itself. In the case of a CMS like PrestaShop, the identification of the connected device's location is based on IPs. This type of geolocation is used by the majority of internet-connected services, such as Netflix, in order to provide a specific catalog for the country where the customer resides. Due to licensing and copyright limitations, not all movies and series available in the streaming platform's catalog can be viewed from Italy, for example. Many users, thanks to streaming platforms, have discovered VPNs in order to bypass geographical blocks and thus access movies and TV series not available in their country.

Statistical services, such as Google Analytics, leverage IP-based geolocation to identify the country from which a visit originates; the accuracy greatly depends on the level of IP masking imposed by GDPR. In fact, this system is a victim of the privacy phobia that pervades European regulations.

It is therefore important to state that geolocation is limited and regulated by European directives and national regulations that have adopted them.

One of the most important rules regarding e-commerce is the prohibition of using geolocation to restrict access to the catalog or show different prices to countries within the European Union. If a visitor, for example, accesses our site from Poland, they must have access to the catalog without geographical limitations, and the taxable amount of the products for sale cannot be different from what we apply in Italy. Of course, it is possible to indicate different shipping costs and/or not provide a courier (in this case, it will be the customer's responsibility to send their own courier to our warehouse to pick up the ordered goods).

Why use Geolocation in PrestaShop?

Geolocation in an ecommerce can have various uses, the simplest of which, activatable in PrestaShop without additional modules, is to inhibit the display of the catalog or the purchase from certain countries. Obviously, as mentioned, this cannot be done for those nations that are part of the European community. The reasons for inhibiting access to certain countries can be as follows:

  • Commercial reasons, due to contracts we cannot sell in certain nations or we do not want to compete with one of our resellers.
  • Political reasons, for example, the current European sanctions against Russia. Or in cases where our products are banned by the regulations of a certain country.
  • Ethical reasons, we do not want our products to be available in a country that does not respect the rights of an ethnic minority, for example.
  • Security reasons, we do not sell, for example, in China and Russia, and considering that the majority of cyber attacks come from those two nations, we may decide not to provide them access to our ecommerce. In this perspective, we can also exclude countries where we do not intend to sell our products, even just to save bandwidth and resources, such as in the case of a pay-per-use CDN.

Geolocation can also be used to provide the customer with information, such as shipping costs and times in their country, without the need for them to register. In the case of PrestaShop, however, it is necessary to use third-party modules to have advanced functionalities.

How accurate is geolocation via IP?

Not much, especially from free databases (like the one provided by MaxMind and used by PrestaShop), it can happen, for example, that a user from Lugano (Switzerland) is located in Milan. This happens because the provider that supplies the internet access is the same, and consequently, the public IP of the connection appears to be located in Italy, even though the connection comes from Switzerland. The difference in the geolocation database is precisely in the accuracy with which they can identify these types of situations. Generally, however, free databases are able to correctly identify countries with few and rare errors, especially when we talk about countries that are not part of the European community. If the user uses a VPN, it will still all be in vain.

How do you activate Geolocation in Prestashop?

As in previous versions of the CMS, to activate geolocation we go to Localization > Geolocation in our BO.

Prestashop in the latest versions 1.7 warns us:

As of December 30, 2019, it is necessary to register on MaxMind to obtain a license key to download geolocation data. Once downloaded, extract the data using WinRAR or Gzip in the /app/Resources/geoip/ directory.

This applies to all PS 1.7 versions, so it is necessary to register on MaxMind to access the free database. Once registered and logged in, we go to download files and download GeoLite2 City, making sure not to confuse it with the CSV version.

It will be enough to unpack the downloaded ZIP file and upload via FTP the file GeoLite2-City.mmdb to the folder /app/Resources/geoip/ of our PrestaShop installation. Once this file is uploaded, the CMS will be able to identify the geographical location by comparing the IPs contained in this DB with those of our visitors.

Once the upload is complete, we can enable geolocation in PrestaShop and decide how it should behave and which countries can access our ecommerce.

To inhibit access to a country, we just need to deselect it from the list in "Select the countries that can access your store"

How to check GeoIP settings?

To check the geolocation settings, we can use a VPN, placing ourselves in the country of interest. The test should be conducted with a browser in incognito mode or different from the one normally used.

Visits coming from disabled countries will receive a 403 error and will not have access to any part of our ecommerce. It is still possible to inhibit only the purchase, switching from "Visitors cannot see your catalog." to "Visitors can see your catalog but cannot place orders."

There are many third-party modules that extend this functionality, most of them rely on this PrestaShop function, so it is necessary to enable it. However, some modules use subscription services, so it is always good to ask the developers how the connection location is identified. Geolocation is a powerful tool, but European directives and GDPR have limited and made its use more complex.

Author: Loris Modena

SENIOR DEVELOPER

Per Ind Loris Modena, owner of Arte e Informatica, started working in the IT sector in 1989 as a system administrator responsible for the maintenance and installation of computer systems. He began programming for the web in 1997, focusing on CGI programming in PERL and later transitioning to programming in PHP and JavaScript. During this time, he became familiar with the Open Source world and the management of Linux servers.

Product added to wishlist