Magento2 Module Geoip
mooore/magento2-module-geoip
Detects a visitor's country using GeoIP data. Provides a REST API and PHP interface to retrieve the country code, with fallback options.
Build Tests
Code Quality
Tested on Magento 2.4.8-p3
Recent Test History
Each release is tested against the latest Magento version at that time.
Looking for Contributors
Composer installation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubMagento 2 GeoIp
Magento 2 module providing basic Geo IP detection.
API
REST
$ curl https://<magento site>/rest/V1/countryCode
"NL"
PHP
<?php
namespace Acme\Component;
use Mooore\GeoIp\Api\CountryCodeInterface;
class SomeComponent
{
/**
* @var \Mooore\GeoIp\Api\CountryCodeInterface
*/
private $countryCode;
public function __construct(CountryCodeInterface $countryCode)
{
$this->countryCode = $countryCode;
}
public function execute(): void
{
//output: Country is NL
echo sprintf('Country is %s', $this->countryCode->get());
}
}
Installation
composer require mooore/magento2-module-geoip
bin/magento setup:upgrade
Configuration
This module has a fallback reliance on several inputs:
-
GeoIP variable
GEOIP_COUNTRY_CODE. -
GeoIP2 variable
COUNTRY_CODE. -
Cloudflare header
CF-IPCountry. - IpInfo.io API.
To be able to fall back on IpInfo.io, follow these steps:
- Have an account at ipinfo.io (usage is free for 50k requests per month).
- Have the ipinfo.io API key.
- Configure it in the Magento 2 backend (Advanced -> System -> GeoIP):
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.