Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Developing with Sitecore Personalize
Data privacy
Before you start sending data
Integrating with Sitecore Personalize
Stream API
Personalize API Flow execution
REST APIs
  • Sitecore Personalize for developers
  • Stream API
  • Sitecore Engage SDK reference
  • Functions
  • EngageServer.event(type, eventData, req[, extensionData])

EngageServer.event(type, eventData, req[, extensionData])

Note

This is a server-side function used for implementing server-side tracking. If you want to implement client-side tracking instead, use the client-side functions.

The event() function sends one of the following:

  • A standard event, for example, ADD, CONFIRM, or CHECKOUT.

  • A custom event with custom data of your choice.

sidebar. Parameters for a standard event

Parameter

Type

Description

type

string

The type of the standard event. If you set this value to any of the Sitecore Personalize reserved event names, for example, VIEW, ADD, or CONFIRM, the event becomes a standard event.

Sitecore Personalize reserved event names:

  • Any event name starting with "SC_"

  • "ADD" - standard ADD event.

  • "ADD_CONSUMERS" - standard ADD_CONSUMERS event.

  • "ADD_CONTACTS" - standard ADD_CONTACTS event.

  • "CAMPAIGN_TRACKING" - internally reserved event. Do not use.

  • "CHECKOUT" - standard CHECKOUT event.

  • "CLEAR_CART" - standard CLEAR_CART event.

  • "CONFIRM" - standard CONFIRM event.

  • "FEEDBACK" - FEEDBACK event.

  • "IDENTITY" - standard IDENTITY event.

  • "INTERACTION" - internally reserved event. Do not use.

  • "ORDER_CHECKOUT" - standard ORDER_CHECKOUT event.

  • "PAYMENT" - standard PAYMENT event.

  • "SUBSCRIPTION" - internally reserved event. Do not use.

  • "SEARCH" - standard SEARCH event.

  • "TRACKING" - internally reserved event. Do not use.

  • "VIEW" - standard VIEW event.

eventData

object

All the event data specific to the standard event type, for example, an ADD event.

req

object

The HTTP request.

[extensionData]

optional

object

Custom data about an event.

Maximum 50 custom attributes of your choice.

sidebar. Parameters for a custom event

Parameter

Type

Description

type

string

The name of the custom event. If you set this value to a custom value of your choice different than Sitecore Personalize reserved event names, for example, "CUSTOM_EVENT_SEARCH" or "myretailsite:CLICKED_POPUP", the event becomes a custom event.

eventData

object

TFhe required attributes that every event object must include, and optional attributes that event objects can include.

req

object

The HTTP request.

[extensionData]

optional

object

Maximum 50 custom attributes of your choice.

Example 15. ORDER_CHECKOUT event

Here's an example of how to use the event() function to send an ORDER_CHECKOUT event. The eventData object must contain all the required attributes for the event type, in this example, for an ORDER_CHECKOUT event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send ORDER_CHECKOUT event
  const eventData = {
  channel: "WEB",
  currency: "EUR",
  pointOfSale: "myretailsite/ireland",
  language: "EN",
  page: "checkout page",
  order: {
    referenceId: "123456",
    orderedAt: "2025-08-23T16:17:16.000Z",
    status: "PURCHASED",
    currencyCode: "EUR",
    price: 200,
    paymentType: "Card",
    cardType: "Visa",
    extensions: [ 
       {
          name: "ext",
          key: "default",
          refundable: true
       }
    ],
    orderItems: [
       {
          type: "MOBILE_PHONE",
          referenceId: "REF-123",
          orderedAt: "2025-08-23T16:17:16.000Z",
          status: "PURCHASED",
          currencyCode: "EUR",
          price: 200,
          name: "Mobile phone of type x",
          productId: "MOBILE_PHONE_TYPE_X",
          quantity: 1,
          extensions: [
             {
                name: "ext",
                key: "default",
                phoneColor: "Gold",
                insurance: false
             }
          ]
       }
    ]
 }
};

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("ORDER_CHECKOUT", eventData, req, extensionData);
  return res;
};

2.0 data model does not support this functionality.



Example 16. ADD event

Here's an example of how to use the event() function to send an ADD event. The eventData object must contain all the required attributes for the event type, in this example, for an ADD event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send ADD event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "products",
    product: {
        name: "GHT 84 Lace Sneaker",
        type: "FOOTWEAR",
        item_id: "SHOES_8475GHT",
        productId: "example_product_id",
        referenceId: "MA-490094",
        orderedAt: new Date().toISOString(),
        quantity: 1,
        price: 7.99,
        currency: "EUR",
        originalPrice: 7.79,
        originalCurrencyCode: "USD"
    }
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("ADD", eventData, req, extensionData);
  return res;
};


Example 17. CONFIRM event

Here's an example of how to use the event() function to send a CONFIRM event. The eventData object must contain all the required attributes for the event type, in this example, for a CONFIRM event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send CONFIRM event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "checkout",
    product: [
      { item_id: "SHOES_8475GHT" }
    ]
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("CONFIRM", eventData, req, extensionData);
  return res;
};


Example 18. CHECKOUT event

Here's an example of how to use the event() function to send a CHECKOUT event. The eventData object must contain all the required attributes for the event type, in this example, for a CHECKOUT event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send CHECKOUT event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "home",
    reference_id: "MA-490094",
    status: "PURCHASED"
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("CHECKOUT", eventData, req, extensionData);
  return res;
};


Example 19. PAYMENT event

Here's an example of how to use the event() function to send a PAYMENT event. The eventData object must contain all the required attributes for the event type, in this example, for a PAYMENT event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send PAYMENT event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "home",
    paymentType: "voucher"
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("PAYMENT", eventData, req, extensionData);
  return res;
};


Example 20. CLEAR_CART event

Here's an example of how to use the event() function to send a CLEAR_CART event. The eventData object must contain all the required attributes for the event type, in this example, for a CLEAR_CART event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send CLEAR_CART event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "home"
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("CLEAR_CART", eventData, req, extensionData);
  return res;
};


Example 21. SEARCH event

Here's an example of how to use the event() function to send a SEARCH event. The eventData object must contain all the required attributes for the event type, in this example, for a SEARCH event.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send SEARCH event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "search result page",
    "product_name": "airSupport",
    "product_type": "RUNNERS"
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("SEARCH", eventData, req, extensionData);
  return res;
};


Example 22. Custom event

Here's an example of how to use the event() function to send a custom event called myretailsite:CLICKED_POPUP. eventData contains all the required attributes for the event data object. extensionData contains the custom data.

RequestResponse
export async function middleware(req) {
  const res = NextResponse.next();

  // Load Engage API
  const engageSettings = {
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>"
  };

  const engageServer = await initServer(engageSettings);

  // Send custom event
  const eventData = {
    channel: "WEB",
    currency: "EUR",
    language: "EN",
    page: "search result page"
  };

  const extensionData = {
    customKey: "customValue"
  };

  await engageServer.event("myretailsite:CLICKED_POPUP", eventData, req, extensionData);
  return res;
};


Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2025 Sitecore