How to profile user location and IP data using hidden visitor form fields and MaxMind Geolocation

  • Updated

If you are using hidden visitor form fields and are using the EPiServer.Personalization.MaxMindGeolocation nuget package you may notice the hidden visitor fields are not tracked in form submissions.



See below for the necessary configuration to get this working. 

  1. Install the EPiServer.Personalization.MaxMindGeolocation package. 
  2. If not already obtained GeoLite2 City and Country files (both csv and mmdb file) from and place in app data folder. 
  3. Add the geolocation section in the web.config. If there is already an existing section, overwrite it. Make sure to update YOUR_NAMESPACE and YOUR_ASSEMBLY within this configuration.
    <geolocation defaultProvider="maxmind2">
    <add name="maxmind2" type="YOUR_NAMESPACE.GeoData.MaxMindGeoLocationCustomProvider, YOUR_ASSEMBLY" databaseFileName="App_Data\GeoLite2-City.mmdb" locationsFileName="App_Data\GeoLite2-City-Locations-en.csv" />
  4. If you have not added the configuration before, you may also need to add the following within <configSections>...</configSections>
    <section name="geolocation" type="EPiServer.Personalization.MaxMindGeolocationProvider, EPiServer.Personalization.MaxMindGeolocation" />
  5. Unzip and add custom geolocation code.
  6. Configure the provider in the ConfigureContainer method of an initialization module that implements IConfigurableModule. Notice the App_Data path below. Modify as needed.

    For instance in an alloy site that would look like this. See the blue text.
    public class DependencyResolverInitialization : IConfigurableModule

    public void ConfigureContainer(ServiceConfigurationContext context)
    //Implementations for custom interfaces can be registered here.

    context.ConfigurationComplete += (o, e) =>
    //Register custom implementations that should be used in favour of the default implementations
    context.Services.AddTransient<IContentRenderer, ErrorHandlingContentRenderer>()
    .AddTransient<ContentAreaRenderer, AlloyContentAreaRenderer>();
    .AddTransient<IGeolocationProvider, MaxMindGeoLocationCustomProvider>()
    .AddTransient<ICustomGeolocationProvider, MaxMindGeoLocationCustomProvider>();

    context.Services.AddMaxMindGeolocationProvider("App_Data\\Geolite2-Country.mmdb", "App_Data\\GeoLite2-Country-Locations-en.csv");
After that future form submissions should give the values for the hidden visitor fields.