Testing Locally With Contact Geolocation and MaxMind

   —   

In this short article, I will give you a quick and easy way to test your project communication with MaxMind database locally, without the need for a publically accessible instance or proxy server of some kind which would normally be needed for accurate testing of Contact location. This test was conducted on Kentico 12 instances but should work in all supported versions. This setup will show you if MaxMind is returning data right out of the gate and will also provide you with some general setup tips for MVC and portal engine sites. 

Setup tips and Information

To first setup geolocation with MaxMind, please go through the steps described in the Kentico documentation: Using geolocation for contacts. You will need to download either the free GeoLite2 City database or purchase the GeoIP2 City database which provides more accuracy and details. Optionally, as mentioned in the documentation, you can use the GeoLite 2 ASN database. To clarify, adding the ASN database would be in addition to your GeoLite2 City or GeoIP2 City database files. In summary, you would have your GeoLite2 City or GeoIP2 City plus the ASN database file added to your MaxMind folder. 

MVC Setup

Out-of-the-box MVC sites will not have the required folder structure setup for MaxMind, therefore, you will need to create these folders to establish the following structure: ~/App_Data/CMSModules/WebAnalytics/MaxMind/ . It is recommended that you create these folders in your projects Admin application (the CMS project) and then add the database files into the MaxMind folder as stated in the documentation.

How to test locally using CMSUserHostAddress

Once you've downloaded your Maxmind database, put the database(s) in the proper folder location, and enable the settings from the documentation. Now you're ready to test it out. 

  1. In the web.config file of your project’s solution (for MVC this will be in the web.config in your Admin application) add to the <appSettings> section <add key="CMSUserHostAddress" value="your local IP address" /> to fake the IP address. For the value you can either use your local IP address (this can be easily found by googling) or another location you wish to test. Below is an example, you would add in the test IP of your choice in the value section.
     
  2.  Once the desired IP is added and saved, open your live site (I suggest doing this in an incognito browser as well).
     
  3.  Once you visit the live site you can open the contact management application within the Kentico administration and view at the bottom, the table of recent visiting contacts. Here, it should display the country of the IP being tested (pictured below). If you wanted further information, you could manage the contact, click the eyeball and view additional information on location such as state, city, zip code depending on what you  mapped in Settings > On-line marketing > Contact Management > Geolocation > Geolocation data to contact fields mapping.

In the examples below I have used a public IP from UK and the free GeoLite2 City database for my test. The second picture demonstrates the “manage contact” view (the eyeball icon)

  

 Alternatively for Portal Engine sites, you can also view this in the web analytics application as well, Web Analyitcs application > Visitors > Countries. Note: This will require enabling of web analytics in Settings first (Enabling web analytics).

That's pretty much all there is to it! Hopefully this is helpful to you. If you run into any Kentico issues during this process, you can reach Kentico Support here.

Share this article on   LinkedIn

Jamie Leask

Kentico Support Engineer