1. Functions

init (deprecated)

Version:
Warning

Deprecated. Use the core package to initialize the Cloud SDK and its packages. See also install and initialize the Cloud SDK.

TypeFunction
Import path@sitecore-cloudsdk/events/browser

Initializes the browser module of the Cloud SDK events package.

Important

Run init before running other functions in the module.

Signature

export async function init(
  settings: BrowserSettings
): Promise<void>

Parameters

NameTypeDescription
settingsBrowserSettingsRequired.

Details about your SitecoreAI instance and cookie settings.

BrowserSettings properties

NameTypeDescriptionValue
sitecoreEdgeContextIdstringRequired.Context ID.Accessible and stored as an environment variable in your app."3axQRoRznWUqHR8B2RSbdo"
siteNamestringRequired.The name of the site.Accessible and stored as an environment variable in your app."myRetailSite"
cookieDomainstringOptional.The top-level domain of your app. The cookie domain ensures that the Cloud SDK stores cookies in the web browser as first-party cookies.Default: your domain.".myretailsite.com"".beta.myretailsite.com""localhost"
cookieExpiryDaysintegerOptional.The number of days before cookies expire.For example, set to 1 for cookies to expire in 1 day.If unset, cookies expire according to the Max-Age set by the web browser.365
cookiePathstringOptional.A URL path that must exist in the requested URL in order to send cookies.Default: "/"."/"
enableBrowserCookiebooleanOptional.Flag to set cookies from the browser side.If using only the browser modules of packages, set to true.If using both the browser and the server modules of packages, set either enableBrowserCookie or enableServerCookie to true, and set the other to false.Default: false.true

Return value

Returns a promise.

Examples

Here's an example page.tsx script showing how to initialize the module:

"use client";
import { useEffect } from "react";
import { init } from "@sitecore-cloudsdk/events/browser";

export default function Home() {
  // Initialize the module ->
  useEffect(() => {
    initEvents();
  }, []);

  const initEvents = async () => {
    await init({
      sitecoreEdgeContextId: process.env.SITECORE_EDGE_CONTEXT_ID,
      siteName: process.env.SITECORE_SITE_NAME,
      enableBrowserCookie: true
    });

    console.log("Initialized the events/browser module.");
  };
  // <- Initialize the module

  return (<></>);
};
If you have suggestions for improving this article, let us know!