Recommendations initialization
The Recommendations initializer configures product recommendation features including personalized suggestions, frequently bought together, and related products. Use initialization to customize recommendation algorithms and data models.
Configuration options
The following table describes the configuration options available for the Recommendations initializer:
| Parameter | Type | Req? | Description |
|---|---|---|---|
langDefinitions | langDefinitions | No | Language definitions for internationalization (i18n). Override dictionary keys for localization or branding. |
models | models | No | Custom data models for type transformations. Extend or modify default models with custom fields and transformers. |
Basic initialization
Initialize the drop-in with default settings:
import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-recommendations';
await initializers.mountImmediately(initialize, {});Language definitions
Override dictionary keys for localization or branding. The langDefinitions object maps locale keys to custom strings that override the drop-in’s default text.
import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-recommendations';
const customStrings = { 'AddToCart': 'Add to Bag', 'Checkout': 'Complete Purchase', 'Price': 'Cost',};
const langDefinitions = { default: customStrings,};
await initializers.mountImmediately(initialize, { langDefinitions });Customizing data models
Extend or transform data models by providing custom transformer functions. Use the models option to add custom fields or modify existing data structures returned from the backend.
The following example shows how to customize the RecommendationUnitModel model for the Recommendations drop-in:
import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-recommendations';
const models = { RecommendationUnitModel: { transformer: (data) => ({ // Add custom fields from backend data customField: data?.custom_field, promotionBadge: data?.promotion?.label, // Transform existing fields displayPrice: data?.price?.value ? `$${data.price.value}` : 'N/A', }), },};
await initializers.mountImmediately(initialize, { models });Available models
The following models can be customized through the models configuration option:
| Model | Description |
|---|---|
RecommendationUnitModel | Transforms RecommendationUnitModel data from GraphQL. |
Configuration types
The following TypeScript definitions show the structure of each configuration object:
langDefinitions
langDefinitions?: { [locale: string]: { [key: string]: string; };};models
models?: { [modelName: string]: Model<any>;};Model definitions
The following TypeScript definitions show the structure of each customizable model:
RecommendationUnitModel
export interface RecommendationUnitModel { displayOrder: number; pageType: PageType; title: string; items: Item[]; totalProducts: number; typeId: string; unitId: string; unitName: string;}