Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML Wrap
clearboth
width341px
alignright
classmenu

Related topics:

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.


Table of Contents

Info

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:

  1. Add the new cookie as an option in the switchable field.
  2. Add the new cookie options in the select field.

Here is the final rule field that the configurations below produce.

Image Added

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.

Info

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:

  1. Add a new content node, visits. This is the internal name of the switchable field option.
  2. Add two properties to the visits node:
    1. label= Visits: The label displayed in the field.
    2. value= visits: The option value stored in the repository.

The configuration should look like this:

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
cookies


Mgnl n
ruleField


Mgnl n
options


Mgnl n
visits


Mgnl p
label

Visits

Mgnl p
value

visits

Mgnl n
weatherLocality


Mgnl n
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:

  1. Add a  visits/options node structure.
  2. In the /options node: 
    1. Add one content node for each option. Our options are one, two, three, four and any. These are the internal names of the options.
    2. Add two properties to each option node:
      1. label<Option label>: The label displayed in the field. 
      2. value<Option value>: The option value stored in the repository.
  3. Optionally, add a sortOptions property to /visits node and set the value to false. This ensures that the options render in configuration order and not alphabetically.

The configuration should look like this:

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
cookies


Mgnl n
ruleField


Mgnl n
options


Mgnl n
fields


Mgnl n
visits


Mgnl n
options


Mgnl n
one


Mgnl p
label

One

Mgnl p
value

1

Mgnl n
two


Mgnl p
label

Two

Mgnl p
value

2

Mgnl n
three


Mgnl p
label

Three

Mgnl p
value

3

Mgnl n
four


Mgnl p
label

Four

Mgnl p
value

4

Mgnl n
any


Mgnl p
label

Any

Mgnl p
value

any

Mgnl p
class

info.magnolia.ui.form.field.definition.SelectFieldDefinition

Mgnl p
defaultValue

any

Mgnl p
sortOptions

false

Mgnl n
tourType


Mgnl n
weatherLocality


Mgnl p
class

info.magnolia.ui.form.field.definition.SwitchableFieldDefinition

Mgnl p
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.

Image Added

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:

  1. 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
  2. Add two properties to each option node:
    1. label<Option label>: The label displayed in the field. 
    2. value<<Rule field name>:<Rule field option value>>: The option value stored in the repository.
  3. Optionally, add a sortOptions property to /valueField node and set the value to false. This ensures that the options render in configuration order and not alphabetically.

The configuration should look like this:

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
cookie


Mgnl n
ruleField


Mgnl n
valueField


Mgnl n
options


Mgnl n
visitsOne


Mgnl p
label

Visits: One

Mgnl p
value

visits=1

Mgnl n
visitsTwo


Mgnl p
label

Visits: Two

Mgnl p
value

visits=2

Mgnl n
visitsThree


Mgnl p
label

Visits: Three

Mgnl p
value

visits=3

Mgnl n
visitsFour


Mgnl p
label

Visits: Four

Mgnl p
value

visits=4

Mgnl n
visitsAny


Mgnl p
label

Visits: Any

Mgnl p
value

visits=any

Mgnl n
tourTypeAny


Mgnl n
...


Mgnl p
class

info.magnolia.ui.form.field.definition.OptionGroupFieldDefinition

Mgnl p
multiselect

true

Mgnl p
sortOptions

false

Download configuration files

As an alternative to manual configuration you can import these XMLs: