2

Using Sitecore 10.1

Xdb.Enabled & Xdb.Tracking.Enabled values are set to true and the layout file has - @Html.Sitecore.VisitorIdentification().

The following values are null.

var country = Sitecore.Analytics.Tracker.Current.Interaction.GeoData.Country;
var city = Sitecore.Analytics.Tracker.Current.Interaction.GeoData.City;
var latitude = Sitecore.Analytics.Tracker.Current.Interaction.GeoData.Latitude;
var longitude = Sitecore.Analytics.Tracker.Current.Interaction.GeoData.Longitude;

I'm assuming, Geolocation services are a part of this version. right?
If yes, is there any config setting to change, to fetch the above values?

3

You'll need to subscribe to the GeoLocation service if you haven't yet. You can do this through the self-service portal which you can find at https://support.sitecore.net. See here for more details on signing up for the service.

If you've subscribed you also need to activate the IP Geolocation service through configurations. You can do this be setting the value GeoIp.PerformLookup to true in webroot\App_Config\Sitecore\DetectionServices.Location\Sitecore.CES.GeoIp.config.

More information can be found here.

2
  • Is it possible to check anywhere in the system (CMS) if the current license has this subscription already?
    – Qwerty
    Apr 12 at 8:59
  • 1
    I don't believe there's anywhere in the CMS itself you can see it, I think you'd have to go through the support portal.
    – Trayek
    Apr 12 at 9:52
3

If you are using Sitecore Geolocation API to achieve this functionality. Hope you raise a request to Sitecore to activate the Sitecore IP Geolocation service. If not you can refer to Sitecore documentation for the same: Set up Sitecore IP Geolocation

  1. Get the Visitor IpAddress like below:
if (Tracker.Current?.Interaction?.Ip != null)
 {
    string ipAddress = new IPAddress(Tracker.Current.Interaction.Ip).ToString();
 }
  1. Now from the IpAddress you can fetch the rest of the details like Region, Country, Post Code, Longitude and Latitude, etc. You can find the code below:
var geoIpManager = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetRequiredService();
var geoIpFetchedData = geoIpManager.GetGeoIpData(ipAddress);
if (geoIpFetchedData.Status == GeoIpFetchDataStatus.Fetched && geoIpFetchedData.WhoIsInformation != null)
  {
    var  country = geoIpFetchedData.WhoIsInformation.Country;
    // other details
  }

It internally uses GeoIpManager Service.

You can use Sitecore.CES.GeoIp.Core.Lookups.LookupManager.GetWhoIsInformationByIp(...), as well but GetWhoIsInformationByIp will be removed in a later version of Sitecore but it will be present for backward compatibility.

var geolocation = Sitecore.CES.GeoIp.Core.Lookups.LookupManager.GetWhoIsInformationByIp(ipAddress);
if (geolocation != null)
  {
    var city = geolocation.City;
    var postCode = geolocation.PostalCode;
    // other details
  }

See the blog post for more reference: Sitecore Geolocation Service API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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