Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore Personalize
Managing accounts and system settings
Identifying guests
Introduction to experiments
Introduction to experiences
Decisioning
View dashboards
Developer Center
Connecting to an external system
Using client-side JavaScript
Using server-side JavaScript
AI in Personalize
Glossary
  • Sitecore Personalize
  • Developer Center
  • Conditions
  • Create a custom condition
  • Condition elements

Condition elements

Before you start, make sure to familiarize yourself with the types of parameters and context parameters for conditions, as well as unsupported JavaScript functions. Use the following structure to declare variables in conditions:

RequestResponse
let nameParam = `[[parametername | type | value1 | {config1: value1, config2: value2 } ]]`;

The following table contains descriptions of condition elements that you can use.

Element

Description

Required

parameter_name

The name of the field that the marketer sees when they add a condition. Example: Cart transaction.

Yes

type

The type of input that the marketer enters when using the condition. Options: string, text, number, enum.

Yes

default_value

The default value for the parameter input.

Optional, but necessary if you want to add variables that the marketer can select from.

configuration

A JSON configuration object that contains name/value pairs, in relation to the type you selected.

Optional

placeholder

A placeholder text that appears in the input box, helping marketers understand the type of input that is expected here.

Optional

Example 1: Condition to identify site visitors by type

This condition identifies site visitors by their type: whether new or returning. It does this by checking for an existing closed web session for the visitor. If the session exists, the visitor is classified as "returning". If the session does not exist, the visitor is considered new. The userType parameter enables marketers to choose whether the visitor must be new or returning to pass the condition.

RequestResponse
(function () {
    var userType = "[[type | enum(new, returning) | | { required: true, placeholder: type }]]";
    var expectedType = "WEB";
    var expectedStatus = "CLOSED";
    var isReturning = false;

    if (guest && guest.sessions && guest.sessions.length > 0) {
         for (var index = 0; index < guest.sessions.length; index++) {
             if (
                 guest.sessions[index] &&
                 expectedType === guest.sessions[index].sessionType &&
                 expectedStatus === guest.sessions[index].status
             ) {
                 isReturning = true;
                 break;
             }
         }
     }

    if (isReturning && userType === "returning") {
         return true;
     } else if (!isReturning && userType === "new") {
         return true;
     } else {
         return false;
     }
})();

Example 2: Condition to check a string value in a data extension

This condition checks for a specific value in a data extension using a string comparison. It loops through all data extensions associated with the visitor and looks for a matching field and value. The condition passes if the value in the specified field matches the one defined using the selected operator, such as === or !==.

RequestResponse
(function () {
    for (var i = 0; i < guest.dataExtensions.length; i++) {
        if (guest.dataExtensions[i].name === "[[ Data Extension Name | string]]"
        && guest.dataExtensions[i].values
        && guest.dataExtensions[i].values.[[Custom Field Name | string]]) {
            return guest.dataExtensions[i].values.[[Custom Field Name]] [[Operator | enum(===,!==)]] "[[ Value | string ]]";
        }
    }
    return false;
})();

Example 3: Condition to check a numerical value in a data extension

This condition checks for a specific numeric value in a data extension. It works similarly to the string match version in the previous example but supports numeric comparison operators such as ===, !==, <, <=, >, and >=.

RequestResponse
(function () {
    for (var i = 0; i < guest.dataExtensions.length; i++) {
        if (guest.dataExtensions[i].name === "[[ Data Extension Name | string]]"
        && guest.dataExtensions[i].values
        && guest.dataExtensions[i].values.[[Custom Field Name | string]]) {
            return guest.dataExtensions[i].values.[[Custom Field Name]] [[Operator | enum(===,!==,<,<=,>,>=)]] [[ Value | number ]];
        }
    }
    return false;
})();

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore