STATEWIZE
Searchโ€ฆ
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:
1
import {StatewizeClient} from 'statewize-client-sdk';
2
โ€‹
3
const stwClient = new StatewizeClient(procee.env.YOUR_TOKEN);
Copied!
5. Report events (see below)

5 types of events you can report:

Journey started

1
await sdk.startJourney({
2
journeyId: integration.journeyId,
3
yourId: "Your ID used to track this journey",
4
yourUserId: "my-user-1234"
5
});
Copied!

Step started

1
const {trackingId} = await sdk.startState({
2
yourId: execId,
3
stateId: state,
4
attachments: [
5
{
6
type: 'file',
7
content: {
8
path: './someRelativeFile.png',
9
}
10
},
11
{
12
type: 'object',
13
content: {
14
object: {
15
thisIs: 'a JSON'
16
}
17
}
18
},
19
]
20
});
Copied!

Sub events (which are occurring as part of a step):

1
await sdk.reportSubEvent({
2
yourId: execId,
3
trackingId,
4
eventName: "Button [btnName] clicked",
5
});
Copied!

Step Ended

1
await sdk.endState({
2
yourId: yourId,
3
stateId: integration.MY_STEP_NAME,
4
output: {
5
thisIs: "The output of the step"
6
},
7
success: true,
8
attachments: [
9
{
10
type: 'text',
11
content: {content: `LOG: info: ${new Date().toISOString()} Selfie verification completed`}
12
},
13
{
14
type: 'url',
15
content: {url: 'https://images.unsplash.com/photo-1566241440091-ec10de8db2e1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2076&q=80'}
16
},
17
{
18
type: 'file',
19
content: {buffer: Buffer.from("test-buffer"), fileName: 'test-text.txt'}
20
}
21
]
22
});
Copied!

Journey Ended

1
await sdk.endJourney({
2
yourId: execId,
3
status: 'complete'
4
});
Copied!
And that's it!
Last modified 2mo ago