Getting Started with JavaScript SDK
Prerequisites
- Castled CEP account is already setup
- Make sure you have conset from from the user before sending user attributes or events to Castled.
The Castled JS SDK enables you to send user attributes and events from your website to Castled. This data can serve as triggers for campaigns or workflows, or be synchronized with your data warehouse for advanced customer segmentation. The following steps will guide you through the process of integrating SDK with your web application.
SDK Initialization
You can use one of the following approaches to add SDK to your website
Add SDK as a code snippet
To integrate the JavaScript SDK with your website, place the following code snippet in the <head>
section of your website.
The above snippet lets you integrate the SDK with your website and load it asynchronously to keep your page load time unaffected.
To load the events SDK synchronously, you can refer to the minified or non-minified versions of the code in the following sections:
— APP-ID
is a unique id associated with your Castled workspace. It can be found in the Castled dashboard at Settings > Api Keys.
Install using npm package manager
you can also use this NPM module to package the library directly into your project.
To install the SDK via npm, run the following command:
Note that this NPM module is only meant to be used for a browser installation.
Since the module exports the related APIs on an already-defined object combined with the Node.js module caching, you should run the following code snippet only once and use the exported object throughout your project:
You can also do this with ES5 using the require
method, as shown:
Exported APIs
The APIs exported by the module are:
load
ready
identify
track
Supported browser versions
Browser | Supported Versions |
---|---|
Safari | v7 or later |
IE | v10 or later |
Edge | v15 or later |
Mozilla Firefox | v40 or later |
Chrome | v37 or later |
Opera | v23 or later |
Yandex | v14.12 or later |
If the SDK does not work on the browser versions that you are targeting, verify if adding the browser polyfills to your application solves the issue.