Skip to main content
Sitecore Documentation
  • Learn
  • Downloads
  • Changelog
  • Roadmap
PersonalizeCloud Portal
Sitecore Personalize
        • Getting started
        • Create a triggered experience
        • Compose a webhook
        • Create a trigger
        • Apply a condition
        • Apply a segment
            • Use FreeMarker snippets
            • Use dynamic decision model data
            • Use guest data
        • Use a decision model
        • Testing via Request Bin
        • Automatic goal tracking for triggered experiences
    • SitecoreAI experiences
    • Using the experience list
    • Manage experience details
    • Set up email notifications
    • View performance analytics
    • View operational data
    • Duplicate, delete, and view details
  • Using client-side JavaScript
  • Glossary
  1. Introduction to experiences
  1. Sitecore Personalize
  2. Introduction to experiences
  3. Introduction to triggered experiences in Sitecore Personalize

Use FreeMarker snippets in an API request for a triggered experience

Sitecore Personalize provides you with FreeMarker snippets that you can copy and paste into the API request. For example, if you selected a decision model to return offers or content, you must include the offers or content in the API request using FreeMarker.

To copy and paste FreeMarker snippets in the API request:

  1. In the API editor, click the API body tab.

  2. On the Snippets tab, browse the available FreeMarker snippets that you can copy and paste into the API body tab.

  3. Click the Copy link next to the code snippet that you want to copy.

  4. Paste the code snippet into the API body tab.

  5. Click Save.

  6. Click to close the API editor.

Check if variable exists

You can use this FreeMarker snippet to check if a variable exists. This helps eliminate errors if there's a null or missing value.

<#if guest.orders[0]??>
	<#-- get last order -->
</#if>

Convert epoch dates and times

Sitecore Personalize manages dates and times in epoch. You can use this FreeMarker snippet to convert dates and times in epoch to a format that FreeMarker can interpret.

<#assign today = .now>
<#assign nowTime = today?long?replace(",","")?number>
<#assign lastSeen = guest.lastSeen?long?replace(",","")?number>


<#assign diffInMinutes2 = ((nowTime - lastSeen)/60000)?round>
<#assign lastSeenDays= ((diffInMinutes2/60)/24)?floor>
<#assign loggedIn24hours = "False">
<#assign nowDate = today?string('yyyy-MM-dd HH:mm:ss')>

<#-- GUEST SESSION DATA -->
<#assign loggedIn24hours = "False">
<#list guest.sessions as sessions>
    <#list sessions.interactions as events>
        <#if events.type == "IDENTITY">
            <#assign identified = "True">
            <#assign identityEventDate = events.date?long?replace(",","")?number>
            <#assign diffInMinutes2 = ((nowTime - identityEventDate)/60000)?round>
            <#if diffInMinutes2 &lt; 1800>
                <#assign loggedIn24hours = "True">
            </#if>
        </#if>
    </#list>
</#list> 

Extract sessions or orders

You can use this FreeMarker snippet to extract sessions from the guest object to a list format that FreeMarker can interpret. You can also use a similar snippet to extract parameters from the orders object.

<#list guest.sessions as sessions>
	<#list sessions.interactions as events>
		<#if events.type == "IDENTITY">
			<#assign identified = "true">
        </#if>
    </#list>
</#list>

Verify number counts

You can use this FreeMarker snippet to verify number counts.

<#if children?number &gt; 0>
    <#if infants?number &gt; 0>
        <#if children?number &lt; 1 || infants?number &lt; 1>
	        <#assign family = "false">
        </#if> 
    </#if>
</#if>
If you have suggestions for improving this article, let us know!

© Copyright 2026, Sitecore A/S or a Sitecore affiliated company.
All rights reserved.

Privacy policySitecore Trust CenterTerms of use