Code Assistant
Code Assistant is only available if Sitecore Stream is enabled for your organization.
Code Assistant is an AI-powered tool in Personalize that understands the prompts you write in natural language, and responds with JavaScript code. The code is tailored to the specific Personalize feature you use the assistant in, such as audience export, conditions, programmables, and session traits.
This topic describes how the Code Assistant works behind the scenes, and how you can best prompt it to enhance your work with JavaScript in Personalize.
Data privacy and security
At Sitecore, data privacy and security are top priorities. Your data is never used to train the LLM, ensuring it remains secure and confidential. Our AI capabilities feature built-in AI guardrails to protect sensitive brand information throughout the marketing workflow. All brand documents and data from interactions with our AI-enabled tools are safeguarded under strict data privacy and security policies.
See the Gen AI FAQ for more information on the use of AI in Sitecore.
Prompting the Code Assistant
When you prompt the Code Assistant, it responds only with generated code using supported JavaScript functions. It doesn’t provide any natural language explanation or feedback. To generate the response, it considers the underlying data schema in your instance of Personalize, the current prompt, and the code that's currently in your code editor, if present. It does not consider your prompt history or previous JavaScript in your code editor.
Therefore, when working with the assistant:
-
Do not copy and paste the current code into your prompt. If there’s code in your editor, the assistant uses it automatically.
-
Prompt the assistant to generate or modify code. The assistant is designed to output JavaScript, not engage in general conversation.
The Code Assistant might make mistakes. Always check your code and test it in the applicable Personalize feature before using it in production.
AI responses can vary. Running the same prompt more than once might produce different results.
Ideas for prompts
Here are a few prompt ideas for the Code Assistant.
Understand and refactor code
You can use the Code Assistant to explain and refactor your code, update the syntax to match your preferences, and add helpful logs to the Personalize test console.
|
Prompt |
Result |
|---|---|
|
Add a code comment to every line to help me understand the code. |
Updates the code with line-by-line comments so you can better understand what it does. |
|
Include more logs in the code so I can review them during testing. |
Updates the code with |
|
Refactor the code to make it shorter. |
Updates the code to be more concise. |
|
Updates the JavaScript syntax to help code readability, depending on your preferences. |
|
Converts the code into an older or newer version of JavaScript syntax, depending on your preferences. |
Conditions
You can use the Code Assistant to quickly create a condition to filter the audience by evaluating specific criteria.
|
Prompt |
Result |
|---|---|
|
Customer purchased in the past 2 days |
Returns Example output: |
|
Returning customer |
Returns Example output: |
|
Customer in a segment |
Returns Example output: |
|
Purchase started but incomplete |
Returns Example output: |
Programmables
You can use the Code Assistant to quickly create a programmable in a decision model to assist with offer decisioning in an experience or experiment.
|
Prompt |
Result |
|---|---|
|
Retrieve last session channel |
Returns the channel from the guest's last session if it's a valid string; returns Example output: |
|
Retrieve the guest's preferred language |
Returns the code of the guest's preferred language if it's a valid string; returns Example output: |
|
Retrieve total orders count |
Returns the number of orders if available; returns Example output: |
|
Retrieve currency code of the most recent order item |
Returns the currency code from the guest's most recent order item if available and valid; returns Example output: |
Session traits
You can use the Code Assistant to easily create a session trait to retrieve and store session-based values for individual customers. You can enter a short prompt or be as descriptive as you like to define the session trait.
|
Prompt |
Result |
|---|---|
|
The most viewed page of the session |
Returns the page viewed most often during the customer's session. Example output: |
|
Count the total view events |
Returns the total number of page VIEW events during the customer's session. Example output: |
|
Last viewed page |
Returns the last page the customer viewed during the session. Example output: |
|
Store time in session |
Returns the total time the customer spent during the session, from the first to the last event. Example output: |
|
Store how many times a customer added something to their cart |
Returns the number of ADD TO CART events in the session. Example output: |
|
Store the top 3 product categories viewed by the guest |
Returns the top three product categories viewed during the session. Example output: |
|
Store the product type name of the item purchased in the last order |
Returns the product type from the customer's most recent purchase. Example output: |