Add the Relevance Module to a Project
Introduction
Goal
Add the Relevance Module to a Bloomreach Experience Manager implementation project.
Background
The Relevance Module is an optional Bloomreach Experience Manager module. This page explains how to add the Relevance Module to a project and configure its data stores in a local Cargo-based development environment. After the steps explained below, the CMS application will contain an additional perspective called Audiences.
Installation through Essentials
The installation of the Relevance Module is supported through Essentials. If you start developing a new project, ensure that you check Make use of Enterprise features, navigate to the Library tab in Essentials, locate the Relevance feature and click Install feature. Essentials then applies most of the steps documented for manual installation below to your project.
Rebuild and restart your project.
Finally, configure the Google API key in order to get a working visitor location map in the Relevance module's Audiences tab.
The Essentials Relevance feature includes bootstrap data to add the relevance system user to the webmaster group. However, due to the way configuration management works, this only works when bootstrapping a new repository and is ignored for existing repositories. Therefore, use one of the following two workarounds:
- For new projects generated using the archetype only, delete the local storage folder before restarting your project after adding the Relevance feature.
- In all other cases, including each redeployment in an existing environment after adding the Relevance feature, perform the manual step Add Relevance System User to Webmaster Group.
Manual Installation Instructions
Start with a Bloomreach Experience Manager project created from the Maven archetype, as explained in Set up a Bloomreach Experience Manager Project. Make sure the top-level pom.xml has the hippo-cms7-enterprise-release as parent.
Add Dependency to Top-level POM
To the top-level pom.xml, add
<dependencies> <dependency> <groupId>com.onehippo.cms7</groupId> <artifactId>hippo-addon-targeting-shared-api</artifactId> <scope>provided</scope> </dependency> </dependencies>
Note the above dependency must not be inside <dependencyManagement>.
To the cargo.run profile, add hippo-addon-targeting-shared-api as shared lib:
<profile> <id>cargo.run</id> <build> <plugins> <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <configuration> <!-- snip --/> <container> <!-- snip --/> <dependencies> <dependency> <groupId>com.onehippo.cms7</groupId> <artifactId>hippo-addon-targeting-shared-api</artifactId> <classpath>shared</classpath> </dependency> </dependencies> </container> </configuration> </plugin>
Add the Elasticsearch Maven Plugin to the Cargo Run Profile
In your local Cargo-based development environment, use the Elasticsearch Maven Plugin to add an Elasticsearch instance to store visits data.
In your project's top-level pom.xml, locate the cargo.run profile. Make the following changes the the profile:
Add the following properties to the profile's <properties> element:
<properties> <es.tcpPort>9300</es.tcpPort> <es.path>${project.build.directory}/storage</es.path> <es.skip.start>false</es.skip.start> <targeting.truncate>true</targeting.truncate> <es.httpPort>9200</es.httpPort> <targeting.bootstrap>false</targeting.bootstrap> <sql.driver>org.h2.Driver</sql.driver> <sql.url>jdbc:h2:${repo.path}/targeting/targeting;AUTO_SERVER=TRUE</sql.url> <sql.username>sa</sql.username> </properties>
Directly after the profile's <plugins> opening element, add the following plugin configuration:
<plugin> <groupId>com.github.alexcojocaru</groupId> <artifactId>elasticsearch-maven-plugin</artifactId> <version>${maven.plugin.elasticsearch.version}</version> <configuration> <clusterName>esDevCluster</clusterName> <httpPort>${es.httpPort}</httpPort> <transportPort>${es.tcpPort}</transportPort> <version>${maven.plugin.elasticsearch.configuration.version}</version> <keepExistingData>true</keepExistingData> <timeout>60</timeout> <skip>${es.skip.start}</skip> </configuration> <executions> <execution> <id>start-elasticsearch</id> <phase>validate</phase> <goals> <goal>runforked</goal> </goals> </execution> <execution> <id>stop-elasticsearch</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin>
This will start up a local Elasticsearch instance when running mvn -P cargo.run. The visits data store is configured to use this local Elasticsearch instance by default.
Add Dependency to CMS Webapp POM
cms-dependencies/pom.xml:
<dependency> <groupId>com.onehippo.cms7</groupId> <artifactId>hippo-addon-targeting-cms-dependencies</artifactId> <type>pom</type> </dependency>
Add Dependency to Site Webapp POM
site/components/pom.xml:
<dependency> <groupId>com.onehippo.cms7</groupId> <artifactId>hippo-addon-targeting-site-dependencies</artifactId> <type>pom</type> </dependency>
Configure an H2 Database JNDI Data Source
In your local Cargo-based development environment, configure a JNDI data source to store requests, visitors and statistics data in the embedded H2 SQL Database.
Add the following JNDI data source configuration to conf/context.xml:
<Resource name="jdbc/targetingDS" auth="Container" type="javax.sql.DataSource" maxTotal="100" maxIdle="10" initialSize="10" maxWaitMillis="10000" testWhileIdle="true" testOnBorrow="false" validationQuery="SELECT 1" timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="60000" username="sa" password="" driverClassName="org.h2.Driver" url="jdbc:h2:${repo.path}/targeting/targeting;MVCC=TRUE"/>
The requests, visitors and statistics data stores are configured to use the jdbc/targetingDS data source by default.
Configure a JNDI Environment Variable for Elasticsearch Properties
In your local Cargo-based development environment, add a JNDI environment variable that contains configuration properties for connecting to Elasticsearch. Add the following JNDI environment variable to conf/context.xml:
<Environment name="elasticsearch/targetingDS" type="java.lang.String" value="{'indexName':'visits', 'locations':['http://localhost:9200/']}" />
The visits data store will use these properties to instantiate a client for connecting to the Elasticsearch webapp that you added previously.
Add Logger to log4j2-dev.xml and log4j2-dist.xml
Add the following logger to conf/log4j2-dev.xml and conf/log4j2-dist.xml:
<Logger name="com.onehippo.cms7.targeting" level="warn"/>
Include the Targeting API in Shared Lib for Distribution
to myproject/src/main/assembly/shared-lib-component.xml, add:
<include>com.onehippo.cms7:hippo-addon-targeting-shared-api</include>
Rebuild and Restart
Stop the application (if it was running), and rebuild and (re)start it as explained in the Getting Started Trail.
Verify that the Elasticsearch webapp is running correctly by browsing to the following URL:
http://localhost:9200/_cat/indices?v
You should see something like this:
health status index pri rep docs.count docs.deleted store.size pri.store.size green open visits 1 0 0 0 159b 159b
Add Relevance System User to Webmasters Group
Using the Console, browse to the node /hippo:configuration/hippo:groups/webmaster.
Add the value hippo-relevance to the multi-valued String property hipposys:members. For example:
/hippo:configuration/hippo:groups/webmaster: hipposys:members: [hippo-relevance, editor]
Configure Google API Key
To enable the map widget in the on the Realtime tab of the Audiences perspective, configure your Google API key.
Using the Console, browse to the node /hippo:configuration/hippo:frontend/cms/hippo-targeting/experience-optimizer-perspective.
Add a String property google.api.key and set its value to your Google API key:
/hippo:configuration/hippo:frontend/cms/hippo-targeting/experience-optimizer-perspective: google.api.key = YOUR_API_KEY
Optional: Add the Collectors Bundle
The Relevance Module contains several collectors that are not bootstrapped by default. To make it easier to add these collectors to a project a Collectors Bundle has been created. The bundle is available as a jar file and contains commonly used collectors, characteristics, and UI plugins. See Add the Collectors Bundle to a Project for more information and instructions.