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.init(settings)

Engage.init(settings)

The asynchronous init() function initializes the Engage SDK on the client side of your app. Call this function after the window object is defined and before you call any other Engage functions.

During initialization, the function creates a browser ID and stores it as a cookie in the browser.

sidebar. Parameters

Parameter

Type

Description

settings

object

Details about your Sitecore Personalize instance and cookie settings.

Example 1. Example: Engage SDK script

Here's an example of how to use the init() function. You must call the init() function asynchronously and save the return value into a variable.

RequestResponse
// Initialize the engage variable
var engage = undefined;

// Create and inject the <script> tag into the HTML
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://d1mj578wat5n4o.cloudfront.net/sitecore-engage-v.1.4.3.min.js";
var x = document.querySelector("script");
x.parentNode.insertBefore(s, x);    

// Initialize the Engage SDK
s.addEventListener("load", async () => {
    const settings = {
        clientKey: "<client_key_PLACEHOLDER>",
        targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
        pointOfSale: "<point_of_sale_PLACEHOLDER>",
        cookieDomain: "<cookie_domain_PLACEHOLDER>",
        cookieExpiryDays: 365,
        forceServerCookieMode: false,
        includeUTMParameters: true,
        webPersonalization: false /* boolean or object. See Settings object for all options. Default: false */
    };
    engage = await window.Engage.init(settings);
});


Example 2. Example: Engage SDK package

Here's an example of how to use the init() function in a React app. You must call the init() function asynchronously and save the return value into a variable.

You can expose Engage functions to the window object by assigning the return value to the window object. You must do this in order to call Engage functions inside your web experience or web experiment in Sitecore Personalize.

In production, you should call the init() function once, then share it across the app using the state management solution of your choice, for example, React Context or Redux.

engage.js:

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

let engage;

const loadEngage = async () => {
  engage = await init({
    clientKey: "<client_key_PLACEHOLDER>",
    targetURL: "<stream_api_target_endpoint_PLACEHOLDER>",
    pointOfSale: "<point_of_sale_PLACEHOLDER>",
    cookieDomain: "<cookie_domain_PLACEHOLDER>",
    cookieExpiryDays: 365,
    forceServerCookieMode: false,
    includeUTMParameters: true,
    webPersonalization: false /* boolean or object. See Settings object for all options. Default: false */
  });

  // Expose Engage functions to the window object:
  window.engage = engage;
};

loadEngage();
export { engage };

App.js:

RequestResponse
import { useEffect } from "react";
import { engage } from "./engage.js";

export default function App() {
    useEffect(() => {
    if (engage !== undefined) {
        // Send VIEW event
    };
    }, []);
// ...
}


Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2025 Sitecore