5

Hi We are using Sitecore 9.0.2 and would like to use Geo Location IP Service. This service has been enabled and its working fine. To access the geo location using API there are two options available which makes me confusing. Can you please suggest which one is correct and benefit of using it.

First Option

var geoIpOptions = new Sitecore.Analytics.Lookups.GeoIpOptions
        {
            Ip = ipAddress,
            MillisecondsTimeout = 1000,
            Id = GeoIpManager.IpHashProvider.ComputeGuid(ipAddress)
        };

        var geoIpResult = GeoIpManager.GetGeoIpData(geoIpOptions);

Second Option :

WhoIsInformation whoIsInformation = LookupManager.GetInformationByIp(ipAddress.ToString());

1 Answer 1

6

The quick answer is that you should always use option #1 over option #2. When you make a request to LookupManager.GetInformationByIp(), this makes a direct service call to map the ip to a location. That might seem to be what you are trying to achieve, but there are several issues with that. Including some of the following:

  • No caching to return previously looked up Ip Addresses
  • Before Sitecore 9, or if you are using your own Geo IP Service, you could be looking up IP addresses unnecessarily, which will cause you to incur more credit expenses ($$$).
  • Subsequent IP Lookups will return results slower than if you returned them from local caching or lookup tables.

Using GeoIpManager will check internal caches and databases to see if that IP has been requested before, which will result in several benefits to your application. Some of the steps that take place include (these may vary based on the version of Sitecore):

  • Access Data Dictionary of recent lookups in memory
  • Access GeoIp Table of Ip Address Mappings
  • Use Service to Lookup Ip
  • Store resolved service ip to geo information in data dictionary/ip table.

It's also important to note that if you are just trying to get the current users country code for example, it probably would make more sense to use the current Tracker, using Sitecore.Analytics.Tracker.Current.Interaction.GeoData.Country will return a string value of the country.

Keeping in mind that with most of the options above, you are unlikely to have the Geo Ip information available on the first page load (unless you run the service calls synchronously which isn't recommended).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.