Magnolia 5.7 reached extended end of life on May 31, 2022. Support for this branch is limited, see End-of-life policy. Please note that to cover the extra maintenance effort, this EEoL period is a paid extension in the life of the branch. Customers who opt for the extended maintenance will need a new license key to run future versions of Magnolia 5.7. If you have any questions or to subscribe to the extended maintenance, please get in touch with your local contact at Magnolia.
This first step in creating a custom cookie trait is to add custom options and values to the preconfigured cookies trait in the Personalization Traits module.
The cookies trait is configured in /modules/personalization-traits/traits/cookies
and the configuration includes a rule and value field.
This page of the tutorial shows you how to configure these fields for a cookie named visits . Please read Cookies trait configuration before you begin.
You can import the XML files provided in the Download configuration files section if you prefer not to configure manually.
Configuring the rule field
The rule field defines values for the trait when you choose an audience. The input entered into the rule field(s) is used to construct a voter. The voter decides if the visitor or visit matches the rule. When the rule is met, Magnolia delivers personalized content.
The rule field options display in the Choose audience dialog in the Pages app. See Personalizing a component for how to access the dialog.
There are two steps to configuring the rule field:
- Add the new cookie as an option in the switchable field.
- Add the new cookie options in the select field.
Here is the final rule field that the configurations below produce.
Adding the switchable field option
Options in the switchable field display in the Choose audience dialog when the user selects Visits in the Cookie field.
To activate the switchable field, in the dialog click Pick trait > Cookie or + > Cookie (if an additional trait exists).
To add the visits
option in
/modules/personalization-traits/traits/cookies/ruleField/options
:
- Add a new content node,
visits
. This is the internal name of the switchable field option. - Add two properties to the
visits
node:label
=Visits
: The label displayed in the field.value
=visits
: The option value stored in the repository.
The configuration should look like this:
Node name | Value |
---|---|
cookies | |
ruleField | |
options | |
visits | |
label | Visits |
value | visits |
weatherLocality | |
tourType |
Adding the select field options
Options in the select field display in the dropdown in the Visits field.
To add the visits
options, in
/modules/personalization-traits/traits/cookies/ruleField/fields
:
- Add a
visits/options
node structure. - In the
/options
node:- Add one content node for each option. Our options are
one
,two
,three
,four
andany
. These are the internal names of the options. - Add two properties to each option node:
label
=<Option label>
: The label displayed in the field.value
=<Option value>
: The option value stored in the repository.
- Add one content node for each option. Our options are
- Optionally, add a
sortOptions
property to/visits
node and set the value tofalse
. This ensures that the options render in configuration order and not alphabetically.
The configuration should look like this:
Node name | Value |
---|---|
cookies | |
ruleField | |
options | |
fields | |
visits | |
options | |
one | |
label | One |
value | 1 |
two | |
label | Two |
value | 2 |
three | |
label | Three |
value | 3 |
four | |
label | Four |
value | 4 |
any | |
label | Any |
value | any |
class | info.magnolia.ui.form.field.definition.SelectFieldDefinition |
defaultValue | any |
sortOptions | false |
tourType | |
weatherLocality | |
class | info.magnolia.ui.form.field.definition.SwitchableFieldDefinition |
transformerClass | info.magnolia.personalization.cookie.CookieFieldTransformer |
Configuring the value field
The value field defines the options that display in the Preview app. The field is used to preview variants when testing personalized content delivery.
Here's the final value field that the configuration below produces.
The value field is an Option group field. The option values should match the option configurations in the rule field.
To add the value field options, in
/modules/personalization-traits/traits/cookies/valueField
:
- Add one content node for each option configured in the rule field. These are the internal names of the options. The node name is arbitrary. Configure one option for each option configured in the rule field
- Add two properties to each option node:
label
=<Option label>
: The label displayed in the field.value
=<<Rule field name>:<Rule field option value>>
: The option value stored in the repository.
- Optionally, add a
sortOptions
property to/valueField
node and set the value tofalse
. This ensures that the options render in configuration order and not alphabetically.
The configuration should look like this:
Node name | Value |
---|---|
cookie | |
ruleField | |
valueField | |
options | |
visitsOne | |
label | Visits: One |
value | visits=1 |
visitsTwo | |
label | Visits: Two |
value | visits=2 |
visitsThree | |
label | Visits: Three |
value | visits=3 |
visitsFour | |
label | Visits: Four |
value | visits=4 |
visitsAny | |
label | Visits: Any |
value | visits=any |
tourTypeAny | |
... | |
class | info.magnolia.ui.form.field.definition.OptionGroupFieldDefinition |
multiselect | true |
sortOptions | false |
Download configuration files
As an alternative to manual configuration you can import these XMLs:
-
visits
ruleField option: -
visits
ruleField field options: -
visits
valueField options:- config.modules.personalization-traits.traits.cookies.valueField.options.visitsOne.xml
- config.modules.personalization-traits.traits.cookies.valueField.options.visitsTwo.xml
- config.modules.personalization-traits.traits.cookies.valueField.options.visitsThree.xml
- config.modules.personalization-traits.traits.cookies.valueField.options.visitsFour.xml
- config.modules.personalization-traits.traits.cookies.valueField.options.visitsAny.xml