Test a condition
Sitecore Personalize enables you to test a condition by running it against a selected guest.
We recommend testing the condition before you publish it, to identify any errors and ensure optimal performance. After changing the code, re-test the condition with the same guest to check the results.
For more advanced use cases that require passing in headers and parameters in the request, you can test an advanced condition.
When you test a condition, Sitecore Personalize tests the JavaScript on the server-side. This ensures that the JavaScript is validated within the context it will be executed in.
If your organization is using Sitecore Cloud Portal, team members with a User, Developer, or Admin role in Cloud Portal can test a condition.
If your organization is not using Sitecore Cloud Portal, you must have an Enterprise Designer role to test a condition.
To test a condition:
-
Open the condition and click Test.
-
In the Test Condition dialog, you can test against the default guest's attributes, or click in the search box and choose Recent to select from a list of recently active guests or Bookmarks to select from a list of bookmarked guests. The system selects a guest who was recently active. Search for a guest by entering one of the following identifiers in the search bar:
-
email address
-
guest reference
-
browser ID - enter bid: in the search bar, followed by the ID. For example: bid:abc123
-
Universal Unique Identifier (UUID) - enter the UUID and select the matching guest reference number. This is Sitecore Personalize's unique identifier for the guest.
NoteIf there is a guest whose data you often use when configuring or testing code, just click the star icon to bookmark the guest so you no longer have to search for them.
-
-
To temporarily modify the guest data (this is only temporary and does not change any attributes associated with the guest), edit the JSON in the code editor.
-
Click Test. The condition runs as it would in production, against the data of the selected guest. The output of the condition displays on the Response tab.
Add guest parameters
You can configure the guest parameters to allow you to view them in the test's response. To achieve this, you must include a function in your condition that calls the guest
context.
To add guest parameters to a condition:
-
In the code editor, include this JavaScript in the code editor to call the
guest
context, as shown here:RequestResponse(function () { return { guest: guest }; })();
-
Click the Condition parameters option to enter the values.
-
Click Test. The output of the condition, including the guest parameters display on the Response tab.
Add a point of sale parameter
You can configure the Point of Sale
parameter to allow you to view it in the test's response. To achieve this, you must include a function in your condition that calls the request
context.
To add a point of sale parameter to a condition:
-
In the code editor, include this JavaScript in the code editor to call to call the
request
context, as shown here:RequestResponse(function () { return { request: request }; })();
-
Click the Experience request option and select the point of sale from the drop-down list.
-
Click Test. The output of the condition, including the
Point of Sale
parameter display on the Response tab
Add tenant parameters
You can configure the tenant
parameters to allow you to view them in the test's response. To achieve this, you must include a function in your condition to call the tenant
context.
To add tenant parameters to a condition:
-
In the code editor, include this JavaScript in the code editor to call the
tenant
context, as shown here:RequestResponse(function () { return { tenant: tenant }; })();
For example, the out-of-the-box Visit date of month (organization time zone) condition includes the
tenant.configurations.timezone
parameter in the JavaScript, as shown here:RequestResponse(function () { load("classpath:moment.js"); load("classpath:moment-timezone.js"); var returnValue = false; var comparison = false; var comparator = "[[is | enum(is, is not) | is | { required: true }]]"; var operatorValue = "[[compares to | enum(is equal to,is greater than,is less than,is greater than or equal to,is less than or equal to,is between) | | { required: true, placeholder: compares to} ]]"; var dayOfMonth = Number("[[number | number | | { required: true, min: 0, max: 31, placeholder: 0 }]]"); var dayOfMonth2 = Number("[[until day | number | | { required: true, min: 0, max: 31, placeholder: 0 }]]"); var tenantTimezone = ""; if (tenant && tenant.configurations && tenant.configurations.timeZone) { tenantTimezone = tenant.configurations.timeZone; } var tenantDate = moment.tz(tenantTimezone).date(); if (operatorValue === 'is between') { comparison = tenantDate >= dayOfMonth && tenantDate <= dayOfMonth2; } else { if (operatorValue === 'is equal to') { comparison = tenantDate === dayOfMonth; } else if (operatorValue === 'is greater than') { comparison = tenantDate > dayOfMonth; } else if (operatorValue === 'is less than') { comparison = tenantDate < dayOfMonth; } else if (operatorValue === 'is greater than or equal to') { comparison = tenantDate >= dayOfMonth; } else if (operatorValue === 'is less than or equal to') { comparison = tenantDate <= dayOfMonth; } } if (comparator === "is") { returnValue = comparison; } else { returnValue = !comparison; } return returnValue; })();
-
Click the Condition parameters option to enter values.
-
Click Test. The output of the condition, including the
tenant
parameters display on the Response tab
Add a print statement
To help debug a condition or understand its flow, you can include print()
statements in your condition. These allow you to view the condition output in the response, up until the point the code throws an error.
To add a print statement to a condition:
-
In the code editor, include a JavaScript for the
print()
statement. For example:RequestResponse(function () { print("first log"); print("second log"); return true; })();
-
Click Test. The output of the condition displays on the Response tab.
-
To view the logs from the
print()
statements, click Logs as shown below: