Contentstack Personalize, is the first edge-optimized personalization platform, seamlessly integrated within Contentstack’s Headless CMS.
The Personalize JavaScript SDK allows you to personalize content for your Contentstack-powered digital properties, including fetching variants for the user, triggering events, setting attributes, etc.
If you have selected Node.js for your project, then use the following command to install Contentstack Personalize.
$ npm i @contentstack/personalize-edge-sdk
You can use npm i
as shown above, if you're using an NPM based project setup.
Now that we have installed the SDK, let's initialize the SDK.
Initializing the SDK is an asynchronous task as it involves fetching the manifest. Ideally, this should be done as early as possible in your application's lifecycle.
import Personalize from '@contentstack/personalize-edge-sdk';
let projectUid = 'your-project-uid';
// Using async-await:
await Personalize.init(projectUid);
You can then fetch the active experiences as follows:
const activeExperiences = Personalize.getExperiences();
Please refer to the API reference for details on how to trigger events, set attributes and more.