@contentstack/personalize-edge-sdk
v1.0.3
Published
![Node.js CI](https://github.com/contentstack/personalize-edge-sdk-js/workflows/Node.js%20CI/badge.svg?branch=main)
Downloads
1,791
Readme
Contentstack Personalize JavaScript SDK
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.
Getting Started
Node.js
If you have selected Node.js for your project, then use the following command to install Contentstack Personalize.
$ npm i @contentstack/personalize-edge-sdk
Browser
You can use npm i
as shown above, if you're using an NPM based project setup.
Initializing the SDK
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.