statewize-client-sdk
    TypeScript icon, indicating that this package has built-in type declarations

    2.5.2 • Public • Published

    STATEWIZE Client SDK 🔍

    Used to report events to STATEWIZE.

    Official docs: https://docs.statewize.com

    USAGE

    1. Add package to your project (NodeJS / React / Anything JS)
    yarn add statewize-client-sdk
    

    OR

    npm install statewize-client-sdk
    
    1. Import and initialize (using the API key from your account)
    import {StatewizeClient} from 'statewize-client-sdk';
    
    const stwClient = new StatewizeClient(procee.env.YOUR_API_KEY);

    You can fetch your API key here.

    1. Download your journey integration map from the journey planner canvas

    1. 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',
      output: {
        zim: 'zoom'
      }
    });

    Attachments

    You can include attachments with state events. Simply provide the attachments in the attachments array.

    Attachment types:

    1. Text
    2. JSON objects
    3. Files
    4. URLs

    example:

      await sdk.endState({
        yourId: `Your ID for this whole journey`,
        stateId: journeyMap.START_HERE, // from step 3 
        success: true,
    
        // optional
        trackingId: `Tracking ID received from startState (optional)`,
    
      // optional
        output: {
          someJsonData: true,
        },
      
        // 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',
              
                // You can also provide file from path instead of buffer.
                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 support@statewize.com

    Keywords

    none

    Install

    npm i statewize-client-sdk

    DownloadsWeekly Downloads

    23

    Version

    2.5.2

    License

    GPL-3.0-only

    Unpacked Size

    70.1 kB

    Total Files

    9

    Last publish

    Collaborators

    • justlev