Skip to main content

Create a custom condition


Explains how to create a JavaScript custom condition.

If you're familiar with JavaScript, you can create a custom condition. A condition enables you to filter an experience or experiment based on real-time visitor behavior.

After you publish the condition, marketers can apply it to an experience or experiment. When the experience or experiment runs, Sitecore Personalize executes the JavaScript on the server-side to validate whether to show the experience or experiment to the particular guest. If the response contains truthy values, Sitecore Personalize will show the experiment or experience to the site visitor.

If your organization is using Sitecore Cloud Portal, team members with a User, Developer, or Admin role in Cloud Portal can create a custom condition.

If your organization is not using Sitecore Cloud Portal, you must have an Enterprise Designer role to create a custom condition.

Before you start, we recommend you familiarize yourself with the types of parameters, context parameters and elements used in conditions, as well as supported and unsupported JavaScript functions.

To create a custom condition:

  1. On the navigation pane, click Developer Center, Conditions.

  2. Click Create condition. Alternatively, you can duplicate and edit an existing condition.

  3. Enter a name for the new condition and click Create.

  4. In the code editor, click Edit to configure the JavaScript. We recommended that you return an object in the response body. You can copy code from another condition to help get you started.


    The value returned in the response can be accessed from the variant API response as 'filter'.

  5. Click the Data tab on the coding pane to copy a guest data model attribute or path and paste into the JavaScript editor. Click the CDP_webtemp_pencilicon.png icon and choose one of the following options:

    • To view a random guest's attributes based on guest type, click in the search box and choose Quick Select Customer or Quick Select Visitor. The system selects a guest who was recently active.

    • To select fields from a specific guest, enter their unique identifier into the search box. For example, if you want to use segment membership as dynamic data, search for a guest who is a member of the segment. You can search for a guest using an email address, other unique identifier or browser ID. To find guests by the browser ID, use the bid: prefix plus the browser ID notation. For example: bid: a38b230c-11eb-4cf9-8d5d-274e9f344925


      If there is a guest whose data you often use when configuring or testing code, click the star icon to bookmark the guest so you no longer have to search for them.

  6. As you define input parameters in the JavaScript coding pane, the parameter names display in the Configuration tab on the right. You must define the condition output using the parameter names, as described in the next section.

Define the condition output

The condition output is a combination of descriptive phrases and input parameters. This is what a user will see when they select a condition to apply to an experiment or experience, as shown below:

Selecting a condition

"The visit has / has not started on a page that compares to page during the current visit"

In this example, has / has not, compares to, and page are input parameters that the user will select values for when they apply the condition to an experiment or experience. We recommend that you phrase the condition output in a way that's similar to how you would structure a sentence.

To define the output:

  1. In the Configuration tab, select the Output option.

  2. Enter the text and the parameters in the Configure text box. This is the what the user will see when they apply the condition to the experiment or experience. As you type, the output displays in the Preview section. Valid parameters are bolded. To see the input parameter values that the user will be able to select from, click the Input option.

    Parameters are case-sensitive and must be wrapped in double square brackets, for example: [[]].


    You must include all the condition parameters in the Configure text box, that are defined in the JavaScript coding editor. Parameters that are defined in the JavaScript but haven't been included in the Configure text box have a red exclamation mark. Click pers_copyParam.png to copy the parameter name and paste it into the Configure text box.

    Parameters that have been included in the Configure text box and are valid have a green checkmark.

    This image shows that the has input parameter is defined in the JavaScript and has been included in the Configure text box. The green checkmark displays to indicate the input parameter was successfully included. The compares to parameter and page parameter have red exclamation marks because although they are included in the Configure text box, they are not wrapped in double square brackets and have an invalid syntax. To make the syntax valid and have the green checkmark display, wrap the parameters in double square brackets.

    Configuring a condition
  3. A preview of the condition output displays on the Configuration tab. This is useful to see how the user will view the condition when applying it to an experiment or experience. Click the Input option to view the parameter values that a user can select for the condition.

  4. Click Test to test the condition using guest data. We recommend testing the condition before you publish it, to identify any errors and ensure optimal performance.