Skip to content

Personalization initialization

You must include the personalization initializer on all pages by adding it to the header.js file.

The initialization code resides in the /scripts/initializers/personalization.js file within the boilerplate.

Functionality

The initialization sets up the following listeners:

EventHandling
cart/updatedRequests the applied customer groups, segments, and cart rules from Adobe Commerce and saves them to a cookie.
authenticatedEnables cart/initialized event processing when a customer logs in and clears the personalization cookie when a customer logs out.
cart/initializedWhen a customer has just logged in, requests the applied customer groups, segments, and cart rules from Adobe Commerce and saves them to a cookie.

Initialization example

Add the following line to the blocks/header/header.js file in the boilerplate (or any other file included for all pages):

import '../../scripts/initializers/personalization.js';