Personalization with geo-based conditions does not work properly on the first visitor request


Description

When using personalization or conditional renderings with rules based on the geographical information of the visitor (such as where the country is equal to specific country), the personalized content might not been presented to the visitor correctly on the first request.

Such behavior occurs because Sitecore is designed not to wait until the GeoIP information has been resolved from a GeoIP lookup provider. This is implemented to keep response times for the website visitors low in situations when the GeoIP resolution process is taking a long time.

Solution

To make Sitecore wait for the GeoIP information even on the first request from a visitor, proceed as follows:

  1. Create a custom processor for the createVisits pipeline:
    namespace Sitecore.Support.Analytics.Pipelines.CreateVisits
    {
    using Sitecore.Analytics.Pipelines.CreateVisits;
    using Sitecore.Configuration;
    using Sitecore.Diagnostics;
    using System;
    public class UpdateGeoIpData : CreateVisitProcessor
    {
    public override void Process(CreateVisitArgs args)
    {
    Assert.ArgumentNotNull(args, "args");
    Assert.ArgumentNotNull(args, "args");
    int intSetting = Settings.GetIntSetting("Analytics.PerformLookup.CreateVisitInterval", 5); // retrieve the delay value from the setting.
    args.Interaction.UpdateGeoIpData(TimeSpan.FromSeconds((double) intSetting)); // wait for the time specified in the Analytics.PerformLookup.CreateVisitInterval setting.
    }
    }
    }
  2. Replace the <processor type="Sitecore.Analytics.Pipelines.CreateVisits.UpdateGeoIpData, Sitecore.Analytics" /> processor with the created one.

The approach overrides the logic of the createVisit pipeline and makes Sitecore wait a certain period of time for the GeoIp information to be resolved. The delay time is configured using the Analytics.PerformLookup.CreateVisitInterval setting. The setting defines the maximum delay to resolve the geographical data from the lookup provider allowed during the first page-request of a new visit.