Code snippets
Here's a list of example JavaScript functions you can use in an audience export.
Guest age
This function returns the guest's approximate age from their date of birth:
Example return value: {"age": "25"}
If you're using Basic mode, you can include this in the output as ${jsResult.age}.
Alternatively, if you're using Advanced mode, the returned JSON object will automatically be included in the output.
Order in previous 24 hours
This function searches for an order completed by the guest in the previous 24 hours. If such an order exists, the JavaScript returns the order reference and order status:
Example return values: {"orderRef": "B-321741", "orderStatus": "PURCHASED"}
If you're using Basic mode, you can include this in the output as ${jsResult.orderRef} and ${jsResult.orderStatus}.
Alternatively, if you're using Advanced mode, the returned JSON object will automatically be included in the output.
Date of most recent session
This function returns the date and time of the guest's most recent session:
(function() {
if (guest.sessions) {
var lastSession = guest.sessions[0];
var date = "";
if (lastSession) {
if (lastSession.events) {
for (var event in lastSession.events) {
if (lastSession.events[event].createdAt) {
date = lastSession.events[event].createdAt;
}
}
}
}
}
// Return the guest's last session date in the "lastSessionDate" variable. Then, reference "lastSessionDate" as ${jsResult.lastSessionDate} on the Output structure tab.
return {
"lastSessionDate": date
};
})();
Example return value: {"lastSessionDate": "2026-04-15T09:11:07.078Z"}
If you're using Basic mode, you can include this in the output as ${jsResult.lastSessionDate}.
Alternatively, if you're using Advanced mode, the returned JSON object will automatically be included in the output.