Add the GeoIP2/GeoLite2 Database to a Project - Bloomreach Experience - Open Source CMS

Add the GeoIP2/GeoLite2 Database to a Project

This feature relies on the GeoLite2 or GeoIP2 database provided by MaxMind.

Introduction

Goal

Enable IP geolocation in Relevance by adding the MaxMind GeoIP2 or GeoLite2 database to a project.

Background

To determine the geographical location attributes such as longitude, latitude, and city name, an IP geolocation database can be added to a project that will be used to convert the visitor’s IP address to geographical information.

Download MaxMin GeoIP2 or GeoLite2 Database

MaxMind provides a database that can be used with Bloomreach Experience Manager's Relevance Module to get geographical location information about visitors. Bloomreach Experience Manager supports both the free of charge GeoLite2 database and the more detailed GeoIP2 City database.

Download either the GeoLite2-City or GeoIP2-City database binary from MaxMind.

Add the Database to a Project

The instructions below assume you are using GeoLite2 but are identical for GeoIP2 except for the database filename (GeoIP2-City.mmdb instead of GeoLite2-City.mmdb).

There are two methods to add the database:

Choose the method that best fits your project configuration and development and deployment processes.

Method 1: As a Maven Dependency

This method creates a small Maven project that wraps the database and is added as a dependency to the Bloomreach Experience Manager implementation project.

Create a Maven project with the following structure:

brxm-maxmind-geolite2
|-- src
|   `-- main
|       `-- resources
|           `-- GeoLite2-City.mmdb
`-- pom.xml

Place the GeoLite2-City.mmdb file in src/main/resources.

Create a root pom.xml with contents similar to the example below.

  • Set the groupId and artifactId following the conventions of your organization.
  • For the artifact version, consider using the GeoLite2 release datestamp.
  • Add your organization's Maven repository to the distributionManagement section.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany</groupId>
  <artifactId>brxm-maxmind-geolite2</artifactId>
  <version>20200114</version>

  <distributionManagement>
    <repository>
      <name>My Company Maven 2 Repository</name>
      <id>maven2-repository</id>
      <url>https://mycompany/maven2/</url>
      <uniqueVersion>false</uniqueVersion>
    </repository>
  </distributionManagement>
</project>
Build the 'brxm-maxmind-geolite2' project and deploy the artifact using mvn install (local) or mvn deploy (remote).

In your Bloomreach Experience Manager implementation project, in cms-dependencies/pom.xml, add the 'brxm-maxmind-geolite2' artifact as a dependency:

    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>brxm-maxmind-geolite2</artifactId>
      <version>20200114</version>
    </dependency>

Method 2: As a Spring Bean Override

This method overrides the Spring bean for the GeoIPService and injects the location of the GeoLite2-City.mmdb database file.

Place the GeoLite2-City.mmdb file in a sensible place in your file system (example assumes /path/to/GeoLite2-City.mmdb).

In your implementation project, create a Spring configuration file at cms/src/main/resources/META-INF/hst-assembly/overrides/targeting-addon-geolite2.xml with the following contents:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

  <bean id="com.onehippo.cms7.targeting.geo.GeoIPService" class="com.onehippo.cms7.targeting.geo.GeoIPServiceImpl">
    <property name="databaseFile" value="/path/to/GeoLite2-City.mmdb" />
  </bean>

</beans>

Don't forget to replace the databaseFile value with the actual path to the GeoLite2/GeoIP2 database in your environment.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?