# Initialization Options
TEMPLATE | TYPE | PURPOSE |
---|---|---|
project | string | Project's draft or production API key. |
savedSession | string | An ID of a saved session to be automatically replayed upon loading. |
container | jQuery selector | Targets page for placement of recommender front-end experience. |
recommendations | number | Number of recommended products to show. |
languageCode | string, ISO language code such as 'en' | Overrides default language detection logic and allows to force the specific language. |
templates | hash | Overrides standard templates, see Templates section. |
events | hash | Allows to handle recommender events and alter Cartographer behavior. See events section. |
translations | hash | Lightweight customization option for out-of-the-box templates. Instead of fully overriding the experience, it is possible to alter the copy of select elements, such as Add To Cart button caption. See Translations section for the list of available translation keys. |
helpers | hash | Enhance the functionality of Handlebars templates by providing JavaScript snippets for advanced data and text manipulation. |
var recommender = new Drive.GuidedRecommender({
project: 'project-draft-or-production-id',
container: $('.placeholder'),
recommendations: 5,
languageCode: 'fr-CA',
template: {
templateName: 'override',
...
},
events: {
eventName: function (data) {
// Handle event.
...
},
...
},
translations: {
'en': {
'add-to-cart': 'Add to Cart',
...
},
...
},
helpers: {
demoHelper: function (url) {
return url + '?demoHelperTest';
},
...
},
...
# Environment Configuration v3
In some cases, it may be desirable to preset questions to already known value at the load time. This could be useful, for example, when some information is already known from the customer information. Alternatively, if a recommender is being reused on multiple pages of a site, and has a branching question that is dependent on the placement of the recommender, it might be desired to preselect a preferred path.
environment
initialization parameter facilitates this ability.
# Configuring Questions
questions
element of environment
parameter allows preselecting question answers. When a question is prefilled, following things happen:
- Prefilled question is removed from the questionnaire experience. If the question was the only question on a page, that page is also hidden.
- Prefilled questions still affect recommendations according to their mapping.
- Prefilled questions trigger page routing according to page rules.
- Back and Next buttons skip over prefilled pages.
- Breadcrumbs and page numbers are adjusted to exclude skipped pages.
- Environment may prefill answers to
all
questions, in which case the page navigation will skip directly to the recommendations page.
See code example below for the sample usage. You can use either question and answer short codes (aka slugs) or their IDs in the configuration.
var recommender = new Drive.GuidedRecommender({
...
environment: {
questions: {
'question-slug-or-id': {
answers: [
'answer-slug-or-id',
'answer-slug-or-id',
...
]
}
}
}
});
// Start built-in flow.
recommender.run();
TIP
Use Do Not Map mapping to create questions that only trigger recommender page logic and routing without affecting recommendations.