statewize-client-sdk
v1.2.1STATEWIZE Client SDK 🔍 ✅
Used to report events to STATEWIZE.
Official docs: https://docs.statewize.com
USAGE
- Add package to your project (NodeJS / React / Anything JS)
yarn add statewize-client-sdk
OR
npm install statewize-client-sdk
- Import and initialize (using the API key from your account)
import {StatewizeClient} from 'statewize-client-sdk';
const sdk = new StatewizeClient(procee.env.YOUR_API_KEY);
You can fetch your API key here.
- Download your journey integration map from the journey planner canvas
- Report events as and when required
const {eventTrackingId} = await sdk.reportEvent({
yourId: "Your Tracking ID",
type: "started",
slug: journeyMap.YOUR_STATE_NAME, // from step 3
yourUserId: 'your-user-1',
});
... some time passes ...
await sdk.reportEvent({
eventTrackingId,
type: "finisned",
slug: journeyMap.YOUR_STATE_NAME, // from step 3
yourUserId: 'your-user-1'
});
Attachments
You can include attachments with state events. Simply provide the attachments in the attachments array.
Attachment types:
- Text
- JSON objects
- Files
- URLs
example:
await sdk.reportEvent({
yourId: `Your ID for this whole journey`,
stateId: journeyMap.START_HERE, // from step 3
type: 'finished',
// optional
eventTrackingId: `Event Tracking ID received from reportEvent`,
// optional:
attachments: [
{
type: 'text',
content: {content: `LOG: info: ${new Date().toISOString()} Selfie verification completed`}
},
{
type: 'url',
content: {url: 'https://images.unsplash.com/photo-1566241440091-ec10de8db2e1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2076&q=80'}
},
{
type: 'file',
content: {buffer: Buffer.from("test-buffer"), fileName: 'test-text.txt'}
},
]
});
Enriching user data
You can provide additional user data for users that you track. We don't know who your users are, and we don't use their
information for any purposes. But for your own logging purposes, if you're interested to attach some rich data about the
users you track - you can do so using setUserData
method.
For example:
await sdk.setUserData({yourUserId: 'user-1234', data: {something: 'important'}});
Switching the execution id
Let's say you've started tracking a journey using one id, but then you have another ID you'd like to use for this specific execution.
For example, you may have started tracking an e-commerce order using an auto-generated ID on the marketing site, but now you'd like to
use your own orderId
- something you didn't have before - for the same execution.
You can do that by calling:
await sdk.switchId({oldId: 'your-old-id', newId: 'your-new-id'});
Please be aware that execution IDs are unique, so the switch may fail if the ID is already used by you in another execution.
For any questions and support, feel free to reach out to [email protected]
Feature Flags
You can use the STATEWIZE SDK in order to fetch available feature-flags. The feature flags will be returned for the environmend that you've initially passed to the SDK's constructor. If no environment is passed, the production environment will be used by default.
const featureFlags = await sdk.getFeatureFlags();
// Will return something like:
// {
// 'your-feature-flag-key': 'someValue',
// 'another-one': false,
// 'now-a-json-one': {
// "zim": "zoom"
// },
// }
We've also prepared a wrapper for you, which would execute its callback only if a feature flag has a truthy value.
For example:
await sdk.withFeatureFlag('your-feature-flag-key', async (featureFlagValue) => {
// This code will be executed ONLY if the value of `your-feature-flag-key` is truthy.
// The parameter received by the callback - `featureFlagValue` - will contain the
// value of the feature flag.
console.log("Hello!");
});
Metadata
- GPL-3.0-only
- Whatever
- Unknown
- released 4/11/2021