- Created by Dominika Kurek, last modified on Nov 14, 2016
The Recommendation Bundle extends the functionality of eZ with a recommendation engine, powered by YOOCHOOSE. It allows you to track the way visitors use your website and suggests recommended content to them based on their behavior.
Installing the Recommendation Bundle
The Recommendation Bundle is installed in a similar way as any other Symfony bundle.
Requirements
- PHP 5.4.4 or higher PHP 5.x version
- Symfony 2.7 or higher Symfony 2.x version
- eZ Platform/Enterprise 2015.01 or above, with the REST API configured to use sessions and publicly open to the YOOCHOOSE servers
- A YOOCHOOSE license
This bundle is independent from the ezrecommendation extension used in legacy, and does not require it.
Step 1: Installation
1. Run the following from your eZ Platform installation root (here with most recent 1.x release):
2. Enable the bundle in app/AppKernel.php
:
3. Import additional routing by adding following lines to your routing.yml
file:
Step 2: Configuration
The bundle's configuration is siteaccess aware. This is an example of settings (config.yml):
The following parameters need to be included in the settings file:
Parameter | Description |
---|---|
yoochoose.customer_id | Your YOOCHOOSE customer ID. |
yoochoose.license_key | Your YOOCHOOSE license key. |
server_uri | The URI your site's REST API can be accessed from. |
recommender.included_content_types | Content Types on which the tracking script will be shown. See Tracking below for more information. |
If content's author or image are stored in different field, you can specify it in parameters.yml:
For example:
Advanced configuration
You can select advanced options for YOOCHOOSE backend using the following settings:
Changing any of these parameters without a valid reason will break all calls to YOOCHOOSE. It can be useful to test the API by mocking the service, or if you have a hosted version of YOOCHOOSE Recommendation service.
Step 3: Clear prod cache
While Symfony dev environment keeps track of changes to yml files, prod does not, so to make sure Symfony reads the new config we clear cache:
Using the Recommendation Bundle
Initial Setup
Your content structure must be mapped to the YOOCHOOSE domain model. This must be done in collaboration with YOOCHOOSE.
Indexing
Public content is automatically indexed. When necessary, eZ Platform will notify YOOCHOOSE of changes to content. Initial import is to be managed with your YOOCHOOSE sales representative. Note that your server's REST API will need to be open to the YOOCHOOSE servers for indexing to be possible.
Tracking
Events from the site need to be sent to YOOCHOOSE so that recommendations can be adapted to visitors. Tracking can be set up in multiple ways, depending on existing constraints.
EzRecommendationBundle
delivers a Twig extension which helps integrate the tracking functionality into your site.
To enable tracking
1. Place the following snippet of code somewhere in the HEAD section of your header template:
2. Configure settings under the recommender.included_content_types
parameter (see the
default_settings.yml
file delivered with this bundle). Here you can define for which content types tracking script will be shown.
You can find more information about tracking in YOOCHOOSE documentation.
Displaying
In order to allow displaying recommendations on your site you must add portions of scripts which will integrate the recommender engine with your site.
Implementation is very easy and can be performed in just a few steps (assuming that the EzRecommendationBundle
is properly configured and enabled in AppKernel.php
):
To enable displaying recommendations
1. Add the following JavaScript assets to your header template:
2. Place a dedicated Twig helper in the place where you want to display recommendations:
Parameters
Parameter | Type | Description |
---|---|---|
contentId | int | In content-based views the Twig variable holding the content id (the content you want to get recommendations for). |
scenario | string | Scenario used to display recommendations. You can create custom scenarios at the YOOCHOOSE dashboard. |
limit | int | Number of recommendations to show. |
contentType | string | Content Types you are expecting in response. |
template | string | HandleBars template name (your templates are stored in the EzRecommendationBundle/Resources/public/views directory. Take a look at default.html.twig which includes a default template that can be used to prepare customized versions). |
fields | array | Fields which are required and will be requested from the recommender engine. These field names are also used inside HandleBars templates. |
Sample integration can take the following form:
You can also bypass named arguments using standard value passing as arguments.
Item ID
The item id is usually set to the viewed ContentId. Depending on requirements, it can be set to a different value, in collaboration with YOOCHOOSE.
If you want to access a specific image alias through API, you need to add the image
parameter to the request url with name of alias as its value, for example:
/api/ezp/v2/ez_recommendation/v1/contenttypes/16?lang=eng-GB&fields=title,description,image,intro,name&page=1&page_size=20&image=rss
to retrieve the rss
alias of the image.
V1.6
As of v1.6, one more parameter is available: sa
, which takes the siteaccess name and defines the siteaccess whose content will be displayed.
Displaying image aliases
Displaying image variations defined with image aliases is not currently supported out-of-the-box.
You can work around this limitation by creating your own template (based on https://github.com/ezsystems/ezstudio-demo/blob/master/app/Resources/EzSystemsRecommendationBundle/views/recommendations.html.twig) or your own Twig extension (based on https://github.com/ezsystems/EzSystemsRecommendationBundle/blob/master/Twig/RecommendationTwigExtension.php#L214).
Troubleshooting
Most operations are logged via the ez_recommendation
Monolog channel. To log everything about Recommendation to dev.recommendation.log, add the following to your config.yml
:
info
by debug
for more verbosity.