DEV Community

Cover image for Building decision models with Sitecore Personalize: usage of programmable nodes
Anna Bastron
Anna Bastron

Posted on • Edited on • Originally published at linkedin.com

2 1

Building decision models with Sitecore Personalize: usage of programmable nodes

In our recent research of Sitecore CDP and Personalize, my colleagues and I looked into decision models, aiming to understand how to dynamically recommend the most relevant content variants based on specific rules. We soon discovered that decision models offer much more than a simple drag-and-drop canvas! In this article I will focus on programmable nodes, an important element of the toolset available to us in Sitecore Personalize.

Decision Model in Sitecore Personalize

Understanding decision models

Decision models are the foundational element of personalised content delivery in Sitecore Personalize. They incorporate several essential components:

  1. Programmable nodes: these nodes are where the magic happens. Technical users familiar with JavaScript can utilise programmable nodes to define custom business logic for dynamic decision making.
  2. Offers: content repositories that can be used for generating recommendations. Offers are what users eventually see on your platform.
  3. External systems: connections to external analytical models or data systems that help drive decisions within the models. A typical reason for using an external system in a decision model is to retrieve data or perform a calculation and then pass it into another decision component.
  4. Decision tables: a powerful tool for crafting decision logic that allows you to map conditions and outcomes efficiently.

The importance of programmable nodes

Programmable nodes are where developers and marketers collaborate to fine-tune the decision models. These nodes allow you to incorporate server-side JavaScript to process and analyse user behaviour data captured from Sitecore CDP across multiple sessions.

Why are programmable nodes so important?

  1. Flexibility: programmable nodes offer unparalleled flexibility, enabling you to implement custom business logic tailored to your specific requirements.
  2. Access to user data: you can access guest objects and their properties from programmable nodes, including data extensions, sessions, orders, and more. This rich data allows you to make decisions and identify which content to display for this guest.
  3. Endless possibilities: with JavaScript expertise at your disposal, there are plenty of possibilities. You can easily write custom code to meet your business expectations and create unique, engaging user experiences.

Creating custom programmable nodes in Sitecore Personalize

To illustrate the process, let's look at an example of a custom programmable node. Imagine you want to calculate the total number of "VIEW" events across all sessions for a given user and output it as an integer.

(function () {
function getNumberOfEvents(sessions, eventType) {
var numberOfEvents = 0;
for (var i = 0; i < sessions.length; i++) {
var session = sessions[i];
for (var j = 0; j < session.events.length; j++) {
var event = session.events[j];
if (event.type === eventType) {
numberOfEvents++;
}
}
}
return numberOfEvents;
}
var numberOfEvents = getNumberOfEvents(guest.sessions, 'VIEW');
return numberOfEvents;
})();

In this code snippet, we define a function called getNumberOfEvents that calculates the number of "VIEW" events within each session and returns the total count.

Custom programmable nodes for unique use cases

Besides event calculations, you can build programmable nodes to cater to various other use cases. For instance, you could check the session state to determine if a user's session is still active:

(function ()
var sessionRef;
if (entity) {
sessionRef = entity.ref;
}
var sessionStatus = "";
for (var i = 0; i < guest.sessions.length; i++) {
var session = guest.sessions[i];
if (session.ref === sessionRef) {
sessionStatus = session.Status;
break;
}
}
return sessionStatus;
})();

Alternatively, you might want to trigger specific actions based on the last event type, such as completion of checkout:

(function ()
function getLastEvent(sessions) {
var lastSession = sessions[sessions.length - 1];
var lastEvent = lastSession.events[lastSession.events.length - 1];
return lastEvent;
}
var lastEvent = getLastEvent(guest.sessions);
return lastEvent.type;
})();

Empowering personalised experiences

Programmable nodes in Sitecore Personalize provide a powerful tool to create highly personalised user experiences. By leveraging server-side JavaScript and collaborating with technical experts, marketers can configure decision models to cater for various scenarios and user preferences. So, unlock the potential of programmable nodes and deliver outstanding content tailored precisely to your users' needs! 🚀

For a detailed guide on creating decision models, check out my colleague's article here. Once you have that foundation, you're all set to start your journey of customisation with programmable nodes. In my next articles I will talk more about other technical features of Sitecore Personalize. Stay tuned! 😊

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up