45 min read
Published:
Hello friends! It's been a while since I last posted, but today I'm excited to share a first look at a newly released feature for Sitecore Personalize and CDP. This new feature combines my two favorite things—personalization and artificial intelligence (AI). It addresses one of the key challenges I've been trying to solve: the difficulty of building experiences and experiments with Sitecore CDP and Personalize.
The Code Assistant is an AI-powered tool that integrates directly into Sitecore Personalize's code editing experience. It helps developers write code specifically within the Sitecore Personalize context. The product has traditionally required specific technologies and JavaScript variations for creating assets—a complexity that challenges even developers familiar with modern JavaScript.
This is where the new Code Assistant will provide significant value for developers. I believe this is just the beginning—there may be opportunities for marketers to use the code assistant to create experiences as well. Last year, I wrote an article Revolutionizing Sitecore Personalize: Unleashing the Power of Generative AI Function Calling on a similar topic, exploring how to use an LLM to generate experiences through prompts. While that approach had limitations and was intended as a proof of concept, it makes me excited to see these innovations coming to the product.
In this initial release, you can use the Code Assistant to craft code for Conditions (compatible with XM Cloud when used alongside Personalize), Session Traits (a recent addition), and Audience Export. You'll find it in any section that requires code writing. While Session Traits and Conditions are straightforward to use, for Audience Export you'll need to specify an output format using the Advanced
option.
For more information about how to use the new feature, refer to the documentation or the release notes.
In my exploration of the Code Assistant, I tested its capabilities with conditions and discovered several key features:
I tested a use case for a Condition that would determine the user's state—specifically whether they were a Visitor or Known user. I provided this prompt to the Code Assistant: Create a Condition that determines the user guest Type. It should allow me to specify the type as a parameter and then returns true or false if the user has that type
. Here's the snippet it generated:
1(function() {2 var specifiedGuestType = "[[guest type | enum(customer, visitor, member) | customer | { required: true }]]";3 var returnValue = false;45 if (guest && typeof guest.guestType === "string") {6 returnValue = (guest.guestType === specifiedGuestType);7 }89 return returnValue;10})();
The output isn't perfect—member and customer aren't valid types, and it doesn't generate a description (such as "Is the current visitor [guesttype]"). Like with all AI tools, we can't blindly trust its suggestions, but it does provide a solid starting point.
One of the most valuable applications I discovered was creating session traits. Let me show you an example of how the assistant helped develop a keyword tracking system:
1(function ai_generated_function() {2 var keywordTracker = {};34 for (var i = 0; i < triggerSession.events.length; i++) {5 var event = triggerSession.events[i];67 if (event.type === 'VIEW' && event.arbitraryData.keywords) {8 var keywords = event.arbitraryData.keywords.split(',');910 for (var j = 0; j < keywords.length; j++) {11 var keyword = keywords[j].trim();12 keywordTracker[keyword] = (keywordTracker[keyword] || 0) + 1;13 }14 }15 }1617 var sortableKeywords = [];18 for (var key in keywordTracker) {19 sortableKeywords.push([key, keywordTracker[key]]);20 }2122 sortableKeywords.sort(function(a, b) {23 return b[1] - a[1];24 });2526 var topFiveKeywords = sortableKeywords.slice(0, 5).map(function(keywordArray) {27 return keywordArray[0];28 });2930 print("Top five keywords: " + topFiveKeywords);31 return topFiveKeywords.length > 0 ? topFiveKeywords : null;32})();33
I haven't used Session Traits before myself, but here's what they do: they let you collect metrics from the current viewing session and tracked events, then use JavaScript to store specific data points back to the guest's profile. For example, you could analyze a user's entire viewing history from their last session to make determinations about them. This capability would greatly enhance the behavioral personalization strategies I covered in my previous article—I'll need to update that piece to incorporate these Session Traits.
As mentioned, the Code Assistant also supports formatting output for Audience Export. While I haven't extensively tested this feature yet, I wanted to note its availability. I plan to cover Audience Exports more thoroughly in a future blog post.
The Sitecore Personalize Code Assistant marks a significant advancement in simplifying personalization development. Though it has current limitations, the tool shows great potential for speeding up code creation and boosting developer efficiency. As it matures, it's likely to become essential to the Sitecore Personalize development process—especially for developers working with conditions and session traits.