Create a condition with the Code Assistant
Code Assistant is only available if Sitecore Stream is enabled for your organization.
You can use the Code Assistant to quickly create a custom condition in Sitecore CDP to filter the segment used in an audience export. Whether you’re a developer who wants to save time or a marketer without JavaScript experience, the Code Assistant helps you generate code by simply describing what you need in natural language.
To create a custom condition with the Code Assistant:
-
In the navigation menu, click Developer center > Conditions.
-
Click Create. Alternatively, you can duplicate and edit an existing condition.
-
Enter a name for the new condition and click Create.
-
In the code editor, click Edit
. -
To open the left-hand pane, click Code Assistant.
-
In the left-hand pane, do one of the following:
-
Enter a prompt describing the logic you want to create. Be specific about the criteria, such as guest attributes (gender, city, country), time frames, and the expected return value. See Prompting the Code Assistant for best practices.
-
Select one of the suggested prompts.
The Code Assistant generates the code. This might take a few minutes.
NoteThe Code Assistant generates code based on your current prompt and any code that's present in the code editor. It does not consider your prompt history or previous codes in the editor.
AI responses can vary. Running the same prompt more than once might produce different results.
After the code is generated, it is labeled with a version number, such as Code Output 1.
-
-
To preview the generated code, click View.
TipIf you've entered multiple prompts, use the View buttons to compare different code outputs.
-
In the Code Output dialog:
-
To insert the generated code into the editor and replace any existing code, click Replace code.
-
To copy the generated code to your clipboard, click Copy code.
ImportantAI-generated code might not always be accurate. Always review and test the code before using it.
-
-
Optionally, after inserting the code, you can do the following in the code editor:
-
Make manual changes to the code if needed.
-
Click Format JS
to format your code changes automatically. -
Click Undo
to revert changes.
-
-
Click Save.
After saving, make sure to define the condition output using the appropriate parameter names before testing it