event

Version:

Type

Function

Import path

@sitecore-cloudsdk/events/browser

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 async function event(
  eventData: EventData
): Promise<EPResponse | null>

Parameters

Name

Type

Description

eventData

EventData

Required.

Data for custom events.

Return value

Returns a promise or null.

Examples

Example 35. 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":

"use client"; // Used only in Next.js App Router
import { event } from "@sitecore-cloudsdk/events/browser";

export default function Component(){
  const sendCustomEvent = async () => {
    const eventData: any = {
      type: "myretailsite:CLICKED_PROMO"
    };

    await event(eventData);

    console.log("Sent custom event.");
  };

  return (
    <div>
      <button onClick={sendCustomEvent}>send custom event</button>
    </div>
  );
};


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