Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore Personalize
Managing accounts and system settings
Identifying guests
Introduction to experiments
Introduction to experiences
Decisioning
View dashboards
Developer Center
Connecting to an external system
Using client-side JavaScript
Using server-side JavaScript
AI in Personalize
Glossary
  • Sitecore Personalize
  • Developer Center
  • Session traits
  • Create a session trait

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:

  1. On the navigation pane, click Developer center > Session traits.

  2. Click Create.

  3. Enter a name for the new session trait. Sitecore Personalize automatically creates a friendlyId when you name the session trait. Click Create.

    Note

    You can modify the friendlyId while creating the session trait, but after the session trait is activated, the ID can no longer be changed. The friendlyId identifies the session trait in the guest profile, and you must reference this ID to access the session trait value.

  4. In the JavaScript section, click Start coding.

  5. 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.

    Write a custom JavaScript code in the code editor to define the value you want to capture in the session trait.
  6. To insert a guest data model attribute or path into your code, on the Data tab, click Edit icon 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 Copy icon next to the attribute you want to copy into your code and click Copy Path as JavaScript.

    Tip

    If 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.

  7. To automatically format and indent the JavaScript code in the code editor, click Format icon.

  8. Click Save.

    Important

    We recommend that you test the session trait before you activate it.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore