@sitecore-cloudsdk/events/server
The server module provides the following functions to capture and send events from the server side:
|
Function |
Description |
|---|---|
|
|
Initializes the module. |
|
|
Sends a |
|
|
Sends an |
|
|
Sends a custom event. |
init(settings, req, res)
Overview
This asynchronous function initializes the module. You must run this function before you can run any other functions in the module.
Parameters
|
Parameter |
Type |
Description |
Required/optional |
|---|---|---|---|
|
|
object |
Details about your SitecoreAI instance and cookie settings. |
Required |
|
|
object |
The HTTP request. |
Required |
|
|
object |
The HTTP response. |
Required |
settings
|
Attribute |
Type |
Description |
Example |
Required/optional |
|---|---|---|---|---|
|
|
string (UUID) |
Accessible and stored as an environment variable in your app. |
|
Required |
|
|
string |
The name of the site. Accessible and stored as an environment variable in your app. |
|
Required |
|
|
boolean |
Whether to set cookies from the server side. The default is If you're using both the |
|
Optional |
Code examples
Next.js
Here's an example middleware.ts script showing how to initialize the module:
pageView(eventData, req[, extensionData])
Overview
This asynchronous function sends a VIEW event.
The VIEW event captures the site visitor's action of viewing a webpage in your app. It triggers every time your webpage loads. You must send VIEW events from all webpages where you want to track site visitor behavior.
JSS apps automatically capture VIEW events, with no coding required.
We recommend that you capture VIEW events on the following webpage types:
-
Home
-
Search results
-
Product description
-
Payment
-
Confirmation
-
Promotional offers
The VIEW event also lets you capture data such as the name of the page where the VIEW event triggered, the referrer URL, UTM parameters, and whether the page view triggered on a personalized page variant created in XM Cloud Pages Personalize.
Parameters
|
Parameter |
Type |
Description |
Required/optional |
|---|---|---|---|
|
|
object |
All the required and optional data about an event. |
Required |
|
|
object |
The HTTP request. |
Required |
|
|
object |
Any custom data you want to collect about an event in addition to what's in This object can contain maximum 50 custom attributes of your choice. Use a flat object structure. Nested objects will be automatically flattened, and keys will be renamed as necessary. |
Optional |
eventData object for VIEW events
|
Attribute |
Type |
Description |
Example |
Required/optional |
|---|---|---|---|---|
|
|
string (uppercase) |
The touchpoint where the user interacts with your brand. For example, for webpages, the channel is |
Must be one of:
|
Required |
|
|
string (uppercase ISO 4217) |
The alphabetic currency code of the currency the user is using in your app. For example, if the user selects Australian dollars as the currency on your website, the currency is |
|
Required |
|
|
string (uppercase ISO 639) |
The language the user is using your app in. For example, if the user selects the Japanese language on your website, the language is This is a custom value of your choice. For server-side events, the default is an empty string. |
|
Optional |
|
|
string |
The name of the webpage where the interaction with your brand takes place. This is a custom value of your choice. For server-side events, the default is an empty string. |
|
Optional |
|
|
string |
The ID of a personalized page variant. |
|
Optional |
|
|
string or null |
The URI of the webpage that linked to the webpage where the event was captured. For server-side events, if you don't set a value, it will be set to |
|
Optional |
|
|
boolean |
Specify whether to add every UTM parameter from the URL of the current webpage to the event object. The default is |
|
Optional |
extensionData object
All attributes are optional.
Code examples
Next.js
Here's an example of how to use the pageView function:
Here's an example eventData object:
By default, VIEW events include UTM parameters. Consider the following URL:
When you send a VIEW event from the previous URL, the event data will contain all the UTM parameters:
Here's an example extensionData object containing custom data:
identity(eventData, req[, extensionData])
Overview
This asynchronous function sends an IDENTITY event.
The IDENTITY event is used to resolve the identity of an anonymous site visitor of your app and turn them into a known customer. When Sitecore CDP receives an IDENTITY event, it runs a linking algorithm to try to match guest data from separate guest profiles, based on your organization's identity rules. We recommend that you learn about identity resolution in Sitecore CDP before you start sending IDENTITY events.
You can optionally include personally identifiable information (PII), such as email, first name, and last name.
Parameters
|
Parameter |
Type |
Description |
Required/optional |
|---|---|---|---|
|
|
object |
All the required and optional data about an event. You can include personally identifiable information (PII) in this object. |
Required |
|
|
object |
The HTTP request. |
Required |
|
|
object |
Any custom data you want to collect about an event in addition to what's in This object can contain maximum 50 custom attributes of your choice. Use a flat object structure. Nested objects will be automatically flattened, and keys will be renamed as necessary. |
Optional |
eventData object for IDENTITY events
|
Attribute |
Type |
Description |
Example |
Required/optional |
|---|---|---|---|---|
|
|
string (uppercase) |
The touchpoint where the user interacts with your brand. For example, for webpages, the channel is |
Must be one of:
|
Required |
|
|
string (uppercase ISO 4217) |
The alphabetic currency code of the currency the user is using in your app. For example, if the user selects Australian dollars as the currency on your website, the currency is |
|
Required |
|
array of objects |
The identifiers that are used to identify the users of your app. |
|
Required | |
|
|
string (uppercase ISO 639) |
The language the user is using your app in. For example, if the user selects the Japanese language on your website, the language is This is a custom value of your choice. For server-side events, the default is an empty string. |
|
Optional |
|
|
string |
The name of the webpage where the interaction with your brand takes place. This is a custom value of your choice. For server-side events, the default is an empty string. |
|
Optional |
|
|
string (lowercase recommended) |
The email address of the guest. |
Optional | |
|
|
string (title case) |
The title of the guest. |
|
Optional |
|
|
string (title case recommended) |
The first name of the guest. |
|
Optional |
|
|
string (title case recommended) |
The last name of the guest. |
|
Optional |
|
|
string |
The gender of the guest. |
|
Optional |
|
|
string (ISO 8601) |
The date of birth of the guest. |
|
Optional |
|
|
string |
The mobile number of the guest. |
|
Optional |
|
|
string |
The phone number of the guest. |
|
Optional |
|
|
array of strings (title case recommended) |
The street address of the guest. |
|
Optional |
|
|
string (title case recommended) |
The city address of the guest. |
|
Optional |
|
|
string (title case recommended) |
The state address of the guest. |
|
Optional |
|
|
string (uppercase ISO 3166-1 alpha-2) |
The country address of the guest. |
|
Optional |
|
|
string |
The postal code of the guest. |
|
Optional |
The identifiers array of objects:
|
Attribute |
Type |
Description |
Example |
Required/optional |
|---|---|---|---|---|
|
|
string |
The unique guest identifier provided by your organization's identity system, such as a Customer Relationship Management (CRM) system. |
|
Required |
|
|
string |
The name of your organization's identity system, external to XM Cloud, that provided the unique guest identifier. |
|
Required |
|
|
string (ISO 8601) |
The date the unique guest identifier expires. This is determined by your organization's identity system. |
|
Optional |
extensionData object
All attributes are optional.
Code examples
Next.js
Here's an example of how to use the identity function:
Here's an example eventData object:
Here's an example extensionData object containing custom data:
event(type, eventData, req[, extensionData])
Overview
This asynchronous function sends a custom event with custom data of your choice.
Using a custom event, you can track any custom behavior of your choice, for example, a site visitor's action of clicking a component or adding a product item to their wish list.
We recommend that you give your event a unique name by including, for example, your site name in the name. Example: myretailsite:ADD_TO_WISH_LIST.
Parameters
|
Parameter |
Type |
Description |
Required/optional |
|---|---|---|---|
|
|
string |
The type of the event. You can set this to any value of your choice that is not a reserved event name. Reserved event names: |
Required |
|
|
object |
All the required and optional data about an event. |
Required |
|
|
object |
The HTTP request. |
Required |
|
|
object |
Any custom data you want to collect about an event in addition to what's in This object can contain maximum 50 custom attributes of your choice. Use a flat object structure. Nested objects will be automatically flattened, and keys will be renamed as necessary. |
Optional |
eventData object for custom events
|
Attribute |
Type |
Description |
Example |
Required/optional |
|---|---|---|---|---|
|
|
string (uppercase) |
The touchpoint where the user interacts with your brand. For example, for webpages, the channel is |
Must be one of:
|
Required |
|
|
string (uppercase ISO 4217) |
The alphabetic currency code of the currency the user is using in your app. For example, if the user selects Australian dollars as the currency on your website, the currency is |
|
Required |
extensionData object
All attributes are optional.
Code examples
Next.js
Here's an example of how to use the event function to send a custom event named "myretailsite:CLICKED_PROMO":
Here's an example eventData object:
Here's an example extensionData object containing custom data: