Module Installation
Steps to enable this module in your custom Broadleaf Commerce project
Steps
Step 1 Pull this dependency into your core/pom.xml
:
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-contenttests</artifactId>
</dependency>
This assumes that you are using the Broadleaf BOM that pins all version information. If not, you will need to also add a
<version>
qualifier
Data Changes
Schema Changes
To add all of the necessary database tables and columns for this module, please follow the Liquibase update documentation.
Admin Security Changes
The data in the following SQL file is required to establish Admin sections and permissions for this module:
classpath:/config/bc/sql/load_content_tests_admin_security.sql
This file is automatically included if you have set blPU.hibernate.hbm2ddl.auto=create
and you have not set import.sql.enabled=false
in your properties files. If you are not using Hibernate's auto DDL process and are using Liquibase, you can add a new changeSet
that references this file:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="broadleaf" id="some-unique-id">
<sqlFile path="config/bc/sql/load_content_tests_admin_security.sql" encoding="utf8" stripComments="true" />
</changeSet>
</databaseChangeLog>
Finally, you can unpack the downloaded .jar
file and look at the files in the config/bc/sql
folder to execute this sql manually.
Load Content Test Data
The Content Test module has two required data elements. The goals for content tests are stored in the table named BLC_CONTENT_TEST_GOAL
.
For sites that want to maintain the Google integration properties in the admin (recommended), the file also adds in the
appropriate records to the BLC_SYSTEM_PROPERTY
table.
You can load the following file to load the Goal list and System Property Settings.
/config/bc/sql/load_content_tests_data.sql
Some implementations may wish to customize this SQL to match their Google Analytics Configuration more closely. The table contains a column named REFERENCE which represents the way the Google Experiments API requires Broadleaf to communicate the Goals for the test. The name column can be changed to other values as appropriate for your installation including specific names that match the goals you have setup in Google Analytics.
Note: In development, you can automatically load this SQL files by adding it to the blPU.hibernate.hbm2ddl.import_files property in the development-shared.properties file.
Load Scheduled Job Data
The Content Test module needs to periodically poll Google Experiments to see which variation is winning. Broadleaf uses this data and an algorithm prescribed by Google to ensure that users see the most appropriate variation based on the stage of the test.
To configure the job, you'll need to run the following file.
/config/bc/sql/load_content_tests_required_jobs.sql
Google reports that experiment data is updated three times a day. This job runs every hour by default and can be configured to run on a different schedule. This job will produce little to no additional load on your system.
Note: In development, you can automatically load this SQL files by adding it to the blEventPU.hibernate.hbm2ddl.import_files property in the development-shared.properties file.
Template Changes
Add the following code to the template that renders your HTML head tag. (head.html in the Broadleaf demo site).
This code should appear just before the call to Google Universal Analytics, if applicable. If Google Tag Manager is used on this site, then the location of this tag is irrelevant.
Note: Having a duplicate Google Universal Analytics tag in addition to a Google Tag Manager Universal Analytics is not recommended.
<blc:google_experiments execute="true" />
You will also need to include the content tests Javascript file. This file allows ajax views that are involved in content tests to report the views back to Google.
To enhance the demo site, you would include the content tests JavaScript file as part of the JavaScript bundle in the footer.html.
<blc:bundle name="heatclinic.js"
mapping-prefix="/js/"
files="BLC.js,
contentTestsClient.js,// <--- THIS IS THE FILE THAT WAS ADDED
heatClinic.js,
cartOperations.js,
checkoutOperations.js,
globalOnReady.js,
manageAccountOperations.js,
reviewOperations.js" />
You'll need to include contentTestClient.js as appropriate for your installation. If you are not using the BLC.ajax function to make ajax calls, then you'll need to examine BLC.js and contentTestsClient.js and make similar modifications to your code if you want to allow experiments on views delivered via ajax.
Additional Steps for Non-Spring Boot Projects
Step 1 Add the blContentTestRequestFilter
to the end of your blPostSecurityFilterChain
. This filter chain is found on the demo site in site/src/main/webapp/WEB-INF/applicationContext-filter.xml
:
<bean id="blPostSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
<sec:filter-chain-map request-matcher="ant">
<sec:filter-chain pattern="/**" filters="
...
blContentTestRequestFilter"/>
</sec:filter-chain-map>
</bean>
Note: If you have a Spring Boot based project, then this step is not necessary. In that case, the filter will be automatically ordered according to its
org.springframework.core.Ordered#getOrder()
return value, when the resource is registered with Spring.