|
There are several ways you can display Cxense Content recommendations on your site, but in most situations we recommend the approach described here. |
Prerequisites
The Cxense Content Integration Guide lists all the steps needed for setting up a content recommendation widget. Here we focus on the last of these steps: showing the widget on your site. Thus, we assume that you have already set up a widget object and a template.
You must also make sure that cx.js script is loaded (on the page where the recommendation widget should appear). This is already taken care of if the page contains the Cxense Analytics script (see the Platform primer). Otherwise, you can use the following script tag:
|
The recommended placement is at the very end of the page, e.g., just before </body>.
Insert a target element
Put an empty div-element with a unique ID where you want the widget to appear.
|
Observe that
-
the widget will actually be injected right before this element,
-
by the term "widget ID", we do not mean the ID of this element (but of the widget object).
Include a small script
You must also include a small script. It is most common to place this right below the div-element, but it can appear anywhere on the page. In this script you express
-
that you want to insert a widget,
-
the widget ID,
-
the ID of the element where you want the widget to appear (described above),
-
whether to use an "embedded" or a "mapped" template (or the URL of the template that should be used), and
-
the initial size of the widget iframe (in pixels).
If you have specified template and style objects as part of your widget configuration, the script will look like this:
|
This is the recommended approach since April 2014.
Notice the line that says: renderTemplateUrl: 'auto'
If you have set up a "mapped render template" on the Cxense CDN, you should specify this instead:
|
If you have a CDN-based template but no mapping (or just want to try out a different template), you can specify the template URL directly instead:
|
By default, the size of the iframe is changed to the actual widget size as soon as the template is rendered. This can be disabled setting "resizeToContentSize: false":
|
Definition of a context-object
Explicit setting of a context-object as defined by /public/widget/data.
Best practice available: how to Using "context" as a dynamic parameter for content-configurations.
|
Automatic resizing
One reason you might want to disable automatic resizing is that it does not always work as expected "out of the box".
For resizing to work properly with CDN-based templates you should make sure that the the rendered iframe contents does not have any (outer) margins.
(If you use template and style objects, this is already taken care of.)
Here is an example where resizing is set up to work correctly: page-newsrecs-2013.html
Observe that in this example the template contains the following CSS:
|
It is easier to set up resizing if you can keep either the width or the height fixed.