Creating custom traits without Java
You can use personalization in Magnolia without writing any Java code by using the cookie trait for just about any kind of personalization feature.
The cookie trait supports multiple cookies. You can configure as many cookies as you like for multiple use cases and use them simultaneously. Cookies are supported also in headless scenarios.
Version 2.1.0 of the Personalization module provides two implementations of cookie traits.
In the new implementation, the
Cookie trait leverages a generalized
NameAndValueTraitDetectorFilter that is also used to retrieve traits from the request header (
collectHeaders) and request parameters (
NameAndValueVoter is then used to render the appropriate content variation according to configuration.
In addition, this implementation comes with the
@TraitType annotation for easier configuration:
# name: is omitted as it is taken from the name of the yaml file
|Use this implementation for personalization of headless SPA projects.
The new implementation is part of the
The deprecated approach is part of the
magnolia-personalization-compatibility submodule and was originally introduced in version 1.1.2 of the Personalization module.
Cookies trait (
info.magnolia.personalization.cookie.Cookies) uses a specialized
CookiesDetectorFilter that can read cookies from the HTTP request with
httpServletRequest.getCookies(), but cannot collect the traits from the request header or request parameters. The
CookieVoter is then used to render the appropriate content variation according to configuration.