Cookies trait configuration

  • New cookie trait implementation in the magnolia-personalization-traits submodule.

  • Older (deprecated) implementation in the magnolia-personalization-compatibility submodule.

Even though in both implementations you can create and use multiple cookies, we recommend using the new implementation since a cookie trait is easily configurable there using the @TraitType annotation.

Property Description

<cookie>

required

Trait name.

The property can be omitted if the definition is done using a YAML configuration file. The value is taken from the name of the file.

$type

required (module version 2.1.x and higher)

Since you are configuring a cookie trait, use cookieTrait as the value.

The $type property defines the trait type for delivery of personalized content. The following types are available:

  • cookieTrait

  • headerTrait

  • requestParameterTrait

The $type property is only required for the new traits. It does not need to be configured for the traits that were present in the older (pre-2.1) versions of the Personalization module:

  • date

  • cookies

  • country

  • visitor

All of these pre-configured traits are now provided by the magnolia-personalization-compatibility submodule.

Due to session security restrictions, the country trait can only be used if Magnolia and an SPA application are on the same domain.

ruleField

required

Field used to define permitted values for the trait. The options display in the Choose audience dialog.

valueField

required

Field used to set permitted values for personalized content delivery. The options display in the Preview app.

converterClass

required (module version 2.0.x and earlier)

Cookie parameter converter (info.magnolia.personalization.cookie.CookieParameterConverter).

defaultPreviewTrait

optional, default is false (module version 2.0.x and earlier)

Displays all cookie trait options in the Preview app by default when set to true.

defaultRuleTrait

optional, default is false (module version 2.0.x and earlier)

Indicates whether the trait should be pre-set in the Choose audience dialog.

enabled

optional (module version 2.1.1 and higher)

Disables the respective trait in the Choose audience dialog when set to false.

traitClass

required (module version 2.0.x and earlier)

Specifies the cookie trait class (info.magnolia.personalization.cookie.Cookies).

voterClass

required (module version 2.0.x and earlier)

Matches the cookie name to the cookie value (info.magnolia.personalization.cookie.CookieVoter). See also Voters.

Configuration examples

New implementation

$type: cookieTrait
ruleField:
  $type: comboBoxField
  name: value
  label: Gender
  datasource: &datasource
    $type: optionListDatasource
    options:
      - name: male
        value: male
      - name: female
        value: female
      - name: other
        value: other
valueField:
  $type: comboBoxField
  label: Gender
  datasource: *datasource
Cookie trait configuration from a light module

The name is omitted as it is taken from the name of the YAML file. In the case below, the name would be cookies from the cookies.yaml file.

<light-module>/traits/cookies.yaml
$type: cookieTrait
ruleField:
  ...
valueField:
  ...

Deprecated implementation

cookies:
  converterClass: info.magnolia.personalization.cookie.CookieParameterConverter
  defaultPreviewTrait: false
  defaultRuleTrait: false
  traitClass: info.magnolia.personalization.cookie.Cookies
  voterClass: info.magnolia.personalization.cookie.CookieVoter
  ruleField:
    class: info.magnolia.ui.form.field.definition.SwitchableFieldDefinition
    transformerClass: info.magnolia.personalization.cookie.CookieFieldTransformer
    options:
      weatherLocality:
        value: weatherLocality
      tourType:
        value: tourType
    fields:
      weatherLocality:
        class: info.magnolia.ui.form.field.definition.SelectFieldDefinition
        defaultValue: any
        options:
          any:
            label: cookies.anyValue
            value: any
          london:
            value: London
          basel:
            value: Basel
      tourType:
        class: info.magnolia.ui.form.field.definition.SelectFieldDefinition
        defaultValue: none
        options:
          any:
            label: cookies.anyValue
            value: any
          none:
            label: cookies.noValue
            value: none
  valueField:
    class: info.magnolia.ui.form.field.definition.OptionGroupFieldDefinition
    multiselect: true
    options:
      weatherLocalityLondon:
        value: weatherLocality=London
      weatherLocalityBasel:
        value: weatherLocality=Basel
      tourTypeAny:
        value: tourType=any
Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules