Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Developing with Sitecore Personalize
Data privacy
Before you start sending data
Integrating with Sitecore Personalize
Stream API
Personalize API Flow execution
REST APIs
  • Sitecore Personalize for developers
  • Stream API
  • Sitecore Engage SDK reference
  • Functions
  • Engage.initServer.handleCookie(req, res)

Engage.initServer.handleCookie(req, res)

The asynchronous initServer.handleCookie() function creates the browser ID cookie on the server side and includes the cookie in the response header. To access this function, you must first call the initServer() function. After you call initServer.handleCookie(), you receive the cookie on the client side in the response header.

Tip

In production, we recommend that you call the initServer.handleCookie() function in a middleware and use try-catch blocks to handle errors.

sidebar. Parameters

Parameter

Type

Description

req

object

The HTTP request.

res

object

The HTTP response.

Example 4. Next app

Here's an example of how to use the initServer.handleCookie() function in a Next app to set cookies from the server.

To set cookies from the server, you must set the forceServerCookieMode attribute to true in the settings object. After you call the initServer.handleCookie() function, the cookie is set in the response header.

RequestResponse
import { initServer } from "@sitecore/engage";

const engageSettings = {
    // ...
    includeUTMParameters: true
};

const engageServer = initServer(engageSettings);

export async function getServerSideProps({ req, res }) {
  await engageServer.handleCookie(req, res);
  return {
    props: {},
  };
};

export default function Home() {
  // ...
};


Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2025 Sitecore