win with us.
We exist to make your business thrive and our greatest reward is our returning clients. Our focus is and always will be on our clients and not on industry awards and accreditations, which could account for why we’ve won so many of them…
Sitecore Geolocation: Don’t call the service directly, it’ll cost ya! .
The IP Geolocation service provides information about the physical location of website visitors when you use Sitecore DMS or xDB.
When working with this function you need to be careful NOT to this call directly:
var geoInfo = LookupManager.GetInformationByIp(clientIp.ToString());
This code always requests information directly from the service by passing the IP Information in the memory cache and in the database, which may lead to excessive charges for the service usage.
When IP information is requested using Sitecore, the following steps are performed:
- Lookup of IP information in the memory cache;
- Lookup of IP information in the database;
- Request to the Geolocation service.
Therefore, you always need to check whether the correct IP information is stored in the Analytics database:
Sitecore 7.5 - Sitecore 8.x: the "GeoIps" collection, Collection database (MongoDB)
Sitecore 6.4.1 - Sitecore 7.2: the "GeoIps" table, Analytics database (SQL)
Starting with the Sitecore 8.1 initial release, the IP Geolocation service is automatically installed, and it just needs to be enabled. Because it is strongly related to the xDB, the Analytics and Tracking must be enabled too for the geolocation to work. After all the setup is done, all we need is the proper code for benefiting from the gathered data. So you would approach this using something like this;
//Get user Geo Location based on IP address (we are using an ExtensionMethod here)
var clientIp = new HttpRequestWrapper(HttpContext.Current.Request).GetClientIpAddress();
Then using that IP address you can do something like this, using GeoIPManager in Sitecore.Analytics.Lookups
if (clientIp != null)
var geoIpOptions = new GeoIpOptions
Ip = clientIp,
MillisecondsTimeout = 1000,
Id = GeoIpManager.IpHashProvider.ComputeGuid(clientIp)
var geoIpResult = GeoIpManager.GetGeoIpData(geoIpOptions);
The geoIpResult.GeoIpData object is of type WhoIsInformation and contains a lot interesting data like country, city, region, latitude, longitude etc.