STATEWIZE
Search…
SDK Integration
How to report events to STATEWIZE
Integrating with STATEWIZE is designed to be simple and quick;
  1. 1.
    Install our SDK (Currently supporting Javascript & NodeJS, more languages coming soon) πŸ”
  2. 2.
    Download your journey integration map (available on the floating menu, on any journey page) πŸ‘€
3. Fetch your API key from your Settings page​
4. Initialise the SDK:
import {StatewizeClient} from 'statewize-client-sdk';
​
const sdk = new StatewizeClient(procees.env.YOUR_TOKEN);
5. Report events (see below)

Real-time monitoring & tracking

When your user starts a journey:

await sdk.startJourney({
journeySlug: 'your-journey-slug',
yourId: "Your ID used to track this journey",
yourUserId: "my-user-1234"
});

Reporting an event (a step) of a journey:

const {eventTrackingId} = await sdk.reportEvent({
yourId: "Your Tracking ID",
type: "started",
slug: journeyMap.YOUR_STATE_NAME, // from step 3
yourUserId: 'your-user-1',
});
​

Updating a previously-reported event (i.e new data available - or it's an asynchronous event which starts at one time and ends later, etc):

​
await sdk.reportEvent({
eventTrackingId,
type: "finisned",
slug: journeyMap.YOUR_STATE_NAME, // from step 3
yourUserId: 'your-user-1'
});
​

Child events (which are occurring as part of a different event):

await sdk.reportEvent({
parentEventTrackingId: eventTrackingId,
type: "finisned",
slug: journeyMap.YOUR_STATE_NAME, // from step 3
yourUserId: 'your-user-1'
});

Journey Ended

await sdk.endJourney({
yourId: execId,
status: 'complete'
});
And that's it!
​

A few notes;

  1. 1.
    Reporting an event without starting a journey - is possible. If you do so - the relevant journey will be found, started, and then an event will be reported.
  2. 2.
    You don't have to split an event into started and finished - you can report it as finished on the first call - it's all up to you, however you'd like the tracking to take place.
  3. 3.
    STATEWIZE allows you to use your own ID by providing a yourId field in various SDK methods. This can be helpful when you have a known ID which you'd like to maintain for subsequent journey tracking purposes, instead of persisting the ID returned from STATEWIZE.
  4. 4.
    Environments - You can set your environment in the constructor of the StatewizeClient, as well as on the startJourney event. An environment can be any of the following: [development, testing, staging, production].