Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Personalization initialization

The Personalization initializer configures personalization features including user preferences, behavioral tracking, and content customization. Use initialization to customize personalization data models and enhance user experience.

Version: 3.0.0-beta1

Configuration options

The following table describes the configuration options available for the Personalization initializer:

ParameterTypeReq?Description
langDefinitionsLangDefinitionsNoLanguage definitions for internationalization (i18n). Override dictionary keys for localization or branding.

Default configuration

The initializer runs with these defaults when no configuration is provided:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-personalization';
// All configuration options are optional
await initializers.mountImmediately(initialize, {
langDefinitions: {}, // Uses built-in English strings
models: {}, // Uses default data models
});

Language definitions

Override dictionary keys for localization or branding. The langDefinitions object maps locale keys to custom strings that override default text for the drop-in.

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-personalization';
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.

Available models

The following models can be customized through the models configuration option:

The following example shows how to customize the CustomModel model for the Personalization drop-in:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-personalization';
const models = {
CustomModel: {
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 });

Configuration types

The following TypeScript definitions show the structure of each configuration object:

langDefinitions

Maps locale identifiers to dictionaries of key-value pairs. The default locale is used as the fallback when no specific locale matches. Each dictionary key corresponds to a text string used in the drop-in UI.

langDefinitions?: {
[locale: string]: {
[key: string]: string;
};
};