EngageServer.event(type, eventData, req[, extensionData])
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 custom event with custom data of your choice.
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.
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;
};
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.
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;
};
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.
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;
};
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.
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;
};
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.
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;
};
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.
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;
};
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.
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;
};