personalize

Version:

Type

Function

Import path

@sitecore-cloudsdk/personalize/server

From the server side, runs interactive experiences and experiments that are live in Sitecore Personalize. Automatically captures UTM parameters from the URL of the webpage where the function runs.

Signature

export async function personalize(
  request: Request,
  personalizeData: PersonalizeData,
  opts?: { timeout?: number }
): Promise<unknown | null | FailedCalledFlowsResponse>

Parameters

Name

Type

Description

request

Request

Required.

The HTTP request.

personalizeData

PersonalizeData

Required.

Event and experiment data.

opts

object

Optional.

Additional personalization options.

Opts properties

Name

Type

Description

Value

timeout

integer

Optional.

The number of milliseconds before the function times out and returns an error.

For example, for the function to time out in 10 seconds, set the value to 10000.

Minimum: 0.

10000

Return value

Returns the API response of the interactive experience or experiment.

Examples

Example 62. Running the personalize 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 personalize function:

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

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

  // Initialize the SDK and the package...

  // Run personalization:
  const personalizeData = {
    channel: "WEB",
    friendlyId: "running_shoes_popup_02"
  };

  const personalizeResponse = await personalize(request, personalizeData);
  console.log("Ran personalization.", personalizeResponse);

  return response;
};

personalizeRes contains the API response that the experience or experiment was configured to return.



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