Create a session trait
Sitecore Personalize lets you create session traits that capture attributes from events, perform calculations on these attributes at the end of a customer's session, and store the results in their guest profile. You can customize the logic of a session trait using JavaScript to meet your specific business needs.
To create a session trait:
-
On the navigation pane, click Developer center > Session traits.
-
Click Create.
-
Enter a name for the new session trait. Sitecore Personalize automatically creates a
friendlyIdwhen you name the session trait. Click Create.NoteYou can modify the
friendlyIdwhile creating the session trait, but after the session trait is activated, the ID can no longer be changed. ThefriendlyIdidentifies the session trait in the guest profile, and you must reference this ID to access the session trait value. -
In the JavaScript section, click Start coding.
-
In the code editor, enter the custom JavaScript code that you want to use to capture the session trait. You can use the provided sample code snippets as a starting point for writing the JavaScript needed for your session traits.
-
To insert a guest data model attribute or path into your code, on the Data tab, click
and do one of the following:-
To select a random guest based on guest type, click in the search box and select Visitor or Customer.
-
To select a specific guest, enter their unique identifier into the search box. You can search for a guest using, for example, an email address, other unique identifier, or browser ID.
After selecting a guest, in the Guest data model tree, click
next to the attribute you want to copy into your code and click Copy Path as JavaScript.TipIf there is a guest whose data you often use when configuring or testing code, click the Bookmark
icon so you no longer have to search for them. -
-
To automatically format and indent the JavaScript code in the code editor, click
. -
Click Save.
ImportantWe recommend that you test the session trait before you activate it.