Content personalization in sitecore8 based on country with Maxmind GeoIP
free Service
free Service
One of my
client requirement was to personalize the sitecore content based on the country(Geo-Ip).
And they were using free geo-ip country database provided by maxmind.
Site core
Personalization (country rules) is tightly coupled with analytic database so we
need to customize the sitecore condition
to call geolite country database file to resolve the country ip address.
Personalization (country rules) is tightly coupled with analytic database so we
need to customize the sitecore condition
to call geolite country database file to resolve the country ip address.
So below is
the step by step process to implement this solution:
the step by step process to implement this solution:
Configure the layout with rule and
condition
condition
Step3. In rule editor, select geo-ip
condition and provide value of compareto and specific country
attribute as below
condition and provide value of compareto and specific country
attribute as below
Step4. Select the presentation content> select the datasource
Not working…ohh missed one step, now one sitecore presentation task has been
done but still personalization condition is point to analytic dll, we need to
override that condition with custom dll, as below:
done but still personalization condition is point to analytic dll, we need to
override that condition with custom dll, as below:
Kindly refer my blog to find the new path
of condition item in sitecore 8
of condition item in sitecore 8
Need to change the type as below:
Class name, Namespace
Below is the sample code for custom class
logic:
logic:
public class LiteCountryCondition<T> : CountryCondition<T> where T : RuleContext { protected override string GetColumnValue(VisitorDataSet.VisitsRow visit) { try { string countryCode = string.Empty; if (Sitecore.Context.Item != null) { LookupService lookupService = new LookupService( HttpContext.Current.Server.MapPath( Sitecore.Configuration.Settings.GetSetting("Sitecore.SharedSource.GeoLiteResolver.DataFile")), LookupService.GEOIP_MEMORY_CACHE); Country country = lookupService.getCountry(HttpContext.Current.Request.UserHostAddress); return country.getCode(); } return countryCode; } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(string.Format("LiteCountryCondition: Exception: {0}, Inner Exception: {1}, LiteCountryCondition : GetColumnValue", ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty), this); return ""; } } }
I Hope you enjoyed this article..
Appreciate to your suggestion and comments
Happy sitecore 🙂