1. Functions

entityView

Version:
TypeFunction
Import path@sitecore-cloudsdk/search/server

Sends an entity view event.

Signature

export async function entityView(
  entityViewEventParams: EntityViewEventParams
): Promise<EPResponse | null>

Parameters

NameTypeDescription
entityViewEventParamsEntityViewEventParamsData for entity page view events.

Return value

Returns a promise.

Examples

Example 80. Running the entityView function

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 entityView function:

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { CloudSDK } from "@sitecore-cloudsdk/core/server";
import { entityView } from "@sitecore-cloudsdk/search/server";
import type { EntityViewEventParams } from "@sitecore-cloudsdk/search/server";

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

  // Initialize the SDK and the package...

  // Send event:
  const eventData: EntityViewEventParams = {
    entity: { entity: "product", id: "1" },
    pathname: "/detail-page/1"
  };

  const entityViewResponse = await entityView(request, eventData);
  console.log("Sent entity view event.", entityViewResponse);

  return response;
}

:::

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