Customizing Personalization
Introduction
Personalization refers to offering different pricing, promotions or content based on the shopper’s attributes, known as traits. For example, an item’s price may only be discounted for shoppers who are over sixty five years old. Personalized pricing is also referred to as Dynamic Pricing or Differential Pricing.
How Cortex Process Traits
Cortex uses Subjects to manage its users. When a user logs in with an access token, a Subject is created and exists for the duration of the request. Personalization traits are modelled as attributes on the Subject and are called SubjectAttributes
. If you have access to the Subject, then you also have access to the user’s traits.
Subject Lifecycle
The Subject is created by the HeaderToSubjectLifecycleFilter
which assembles the Subject from HTTP inputs including the role, scope, and the user’s identity details. This filter takes the traits sent through the x-ep-user-traits
HTTP header and adds them to the subject’s attributes. Subject attributes are automatically added to the Commerce Engine Selling Context and can influence pricing, promotions, and dynamic content delivery.
Cortex internally infers traits using SubjectAttributeLookupStrategy
classes that contribute additional SubjectAttributes
to the Subject. As with the x-ep-user-traits
HTTP header, the SubjectAttributes
are automatically added to the Commerce Engine Selling Context and can influence pricing, promotions and dynamic content delivery.
The image below describes an overview of the Subject’s lifecycle.
How to configure a trait’s precedence
With multiple SubjectAttributeLookupStrategy
implementations registered with the Cortex OSGi container, attributes can potentially overlap. Therefore, lookups are evaluated in specific order to ensure the results returned for each request are consistent.
SubjectAttributeLookupStrategy
implementations are configured with an OSGi Service Ranking to control the relative ordering they are evaluated in. Highest ranking lookups runs first and the first lookup wins. Out of the box, the traits specified using the x-ep-user-traits
HTTP header are evaluated after any traits inferred using SubjectAttributeLookupStrategy
. For example, if the locale trait is passed using x-ep-user-traits
HTTP header, then the LocaleSubjectAttributeLookupStrategy
(rank 100) runs first, and HeaderUserTraitAttributeLookupStrategy
(rank -1) runs last.
Service ranking attributes are optional. If rankings are not specified, then the SubjectAttributeLookupStrategy
is assigned a default ranking of zero, which means it runs last. A SubjectAttributeLookupStrategy
will not override traits supplied by previous lookups. Ensure to watch when ordering your lookups.
The following traits are provided out of the box:
Bundle | Trait Lookup | Service Ranking |
---|---|---|
ep-rs-subject-lookup-epcommerce | LocaleSubjectAttributeLookupStrategy | 100 |
ep-rs-subject-lookup-epcommerce | CurrencySubjectAttributeLookupStrategy | 100 |
ep-rs-subject-impl | HeaderUserTraitAttributeLookupStrategy | -1 (last by default) |
How to configure the traits header size
Your Cortex application may require large amounts of personalization information in the traits header and the default header size (8K) may not be large enough. To increase header size, use the configurations provided by your web server. Changes are not required in Cortex to handle larger headers.