Creating a custom cookie trait without Java

This tutorial shows you how to create a custom cookie trait without writing any Java code. All you need is to configure a custom cookie trait and write some FreeMarker and JavaScript code.

Example use case

In this tutorial, we use a common business use case as an example. We create a custom cookie that is used to personalize a component based on the number of times a user visits a specific page. On the assumption that more page visits mean an increasing interest in our product, we progressively display personalized components offering incentives and discounts to entice the user to make a purchase.

More specifically, in the tutorial:

  • A cookie named visits is set.

  • The cookie keeps count of the number of times a user visits the page.

  • On the visitor’s first visit no personalized component displays.

  • On the second and subsequent visit different personalized components offering progressively larger discounts display.

Cookies can be used to create just about any kind of personalization feature and you can adapt the example to suit your needs or use it as inspiration for your own custom cookies.

Tutorial structure and work method

The tutorial uses the DX Core demo bundle and is divided into two sections:

The best way to learn is to do it yourself, so we recommend that you recreate the tutorial from scratch and start by installing a DX Core bundle.


DX Core



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
6.3 beta

Magnolia 6.3 beta

Magnolia 6.3 is in beta. We are updating docs based on development and feedback. Consider the 6.3 docs currently in a state of progress and not final.

We are working on some 6.3-beta known issues during this phase.