All Articles

Sitecore Engage SDK

Introduction

Sitecore Engage is a JavaScript library for sending behavioral data from a web application to Sitecore CDP. It is also compatible with Typescript. In this article, we discuss the capabilities of the SDK.

Installation

Sitecore Engage SDK can be installed on any javascript web application. You would need Node.js and npm. You would also need your Sitecore CDP client key, target URL, and point of sale for configuration.

Run the below command to install:

npm install @sitecore/engage

Usage

Sitecore recommends having an async function to initialize and call the page view event, which can be called in the Effect Hook for a React.js application.

The function would look as below:

const loadEngage = async () => {
  // Load Engage API
  const engage = await init({
    clientKey: "{client_key_PLACEHOLDER}", // for example, "ZpHxO9WvLOfQRVPlvo0BqB8YjGYuFfNe"
    targetURL: "{stream_api_target_endpoint_PLACEHOLDER}", // for example, "https://api-engage-eu.sitecorecloud.io"
    cookieDomain: "{cookie_domain_PLACEHOLDER}", // for example, ".beta.myretailsite.com"
    cookieExpiryDays: 365,
    forceServerCookieMode: false,
  });

  // Send VIEW events
  engage.pageView({
    channel: "{channel_PLACEHOLDER}", // for example, "WEB"
    currency: "{currency_PLACEHOLDER}", // for example, "EUR"
    pointOfSale: "{point_of_sale_PLACEHOLDER}", // for example, "myretailsite/ireland"
  });
};
  • The init() function will initialize the client. The clientKey and the targetURL are mandatory parameters to be used. These parameters should ideally be stored as environment variables.
  • The pageView() function will be used to register a page view event. The channel, currency, and pos (Point of Sale) are mandatory parameters. You can also pass language, page (Page Location Path), pageVariantId.

The SDK currently only offers the page view event. It does look like there are other events also in the SDK. But, only the page view event is available as part of the type returned by the init function.

I will be further following the SDK and keep this article updated.

References

Published Feb 14, 2023

Sitecore MVP Technology 2024-23. Web Developer with rich experience in Sitecore and ASP.NET MVC.