Code Assistant
Code Assistant is only available if Sitecore Stream is enabled for your organization.
Code Assistant is an AI-powered tool in CDP that understands the prompts you write in natural language, and responds with JavaScript code. The code is tailored to the specific CDP 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 CDP.
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 CDP, 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 CDP 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 CDP 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. |
Audience export
You can use the Code Assistant in an audience export in the JavaScript code editor to compute data in addition to what's already in the guest profile. This lets you enrich the data that you export from Sitecore CDP.
After generating code on the JavaScript tab, make sure to include the attributes in the output on the Output structure tab by using the ${jsResult.objectKeyName} notation.
|
Prompt |
Result |
|---|---|
|
Export number of sessions in last 30 days |
Returns the number of sessions the guest has had in the past month. Example output: RequestResponse |
|
Export the total value of the last 10 orders |
Returns the total value of the guest's last 10 orders. Example output: RequestResponse |
|
Export average order price |
Returns the average price of all the guest's orders. Example output: RequestResponse |
|
Export customer loyalty points |
Returns the guest's total number of loyalty points if your organization captures that information using data extensions. Example output: RequestResponse |
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: RequestResponse |
|
Returning customer |
Returns Example output: RequestResponse |
|
Customer in a segment |
Returns Example output: RequestResponse |
|
Purchase started but incomplete |
Returns Example output: RequestResponse |
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: RequestResponse |
|
Count the total view events |
Returns the total number of page VIEW events during the customer's session. Example output: RequestResponse |
|
Last viewed page |
Returns the last page the customer viewed during the session. Example output: RequestResponse |
|
Store time in session |
Returns the total time the customer spent during the session, from the first to the last event. Example output: RequestResponse |
|
Store how many times a customer added something to their cart |
Returns the number of ADD TO CART events in the session. Example output: RequestResponse |
|
Store the top 3 product categories viewed by the guest |
Returns the top three product categories viewed during the session. Example output: RequestResponse |
|
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: RequestResponse |