event

Version:

Type

Function

Import path

@sitecore-cloudsdk/events/server

Sends a custom event with custom data.

Note

The event function can also send a standard event, such as IDENTITY, ORDER_CHECKOUT or SC_SEARCH events if the correct payload is provided.

Signature

export function event<NextRequest>(
  request: NextRequest,
  eventData: EventData
): Promise<EPResponse | null> 

Parameters

Name

Type

Description

request

NextRequest

Required.

The HTTP request.

eventData

EventData

Required.

Data for custom events.

Return value

Returns a promise.

Errors

Examples

Example 48. Running the event function

Next.js

Note

To run this function, you have to first initialize the Cloud SDK.

See more examples and other data you can include in the event.

Here's an example of how to use the event function to send a custom event named "myretailsite:CLICKED_PROMO":

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { CloudSDK } from "@sitecore-cloudsdk/core/server";
import { event } from "@sitecore-cloudsdk/events/server";

export default async function middleware(request: NextRequest) {
  const response = NextResponse.next();

  // Initialize the SDK and the package...

  // Send event:
  const eventData: any = {
    type: "myretailsite:CLICKED_PROMO"
  };

  const eventResponse = await event(request, eventData);
  console.log("Sent custom event.", eventResponse);

  return response;
};


If you have suggestions for improving this article, let us know!