Skip to main content

4. Build the Journey

A Journey is a flow of steps that the SDK runs on the device. Each step reads from and writes to the JourneyContext — a per-execution variable bag — so later steps can use what earlier steps produced.

Create a draft

  1. Open Journeys in the Orchestrator.
  2. Click + to start a new Journey. The Journey Editor opens on the Basics and Audience section.

Journey Editor — Basics

[#03] Journey Editor — Basics and Audience

  1. Fill in:
    • Title: Hello World
    • Programmatic name: hello_world (this is the unique identifier your host app will use — see running Journey in your app.
    • Description: A first DataSapien journey that greets the user.
    • Tags: add a tag like getting-started so your app can filter for it.
    • Target Audience: select the built-in All Audience. (More on Audiences later.)
    • Leave participants as Open-ended.

Design the flow

Move to the Journey Flow section. You'll use the Flow Designer to drag five steps onto the canvas and connect them.

The flow is:

Start → MeData step → Question step → Script step → Screen step → End

Journey flow on the canvas

[#04] The five-step Hello World flow on the canvas

MeData step — collect favorite_color

Drag a MeData step between Start and the next step. Double-click it to open the MeData Usage Editor and select your favorite_color Definition.

When this step runs, the SDK shows the question you authored on the MeData Definition, stores the answer in the on-device data vault, and puts it into the JourneyContext under the key favorite_color.

MeData Usage Editor

[#05] Selecting favorite_color in the MeData Usage Editor

Question step — ask for the user's name

Drag a Question step next. Double-click it to open the Question Editor and configure:

  • Question text: "What's your name?"
  • Free-form answer (no predefined choices), single answer.
  • JourneyContext variable: user_name.

After this step runs, user_name is available in the JourneyContext.

Question Editor

[#06] The Question Editor configured with "What's your name?"

Script step — compose the greeting

Drag a Script step next. Double-click to open the Script Editor and paste:

// Read values that earlier steps put into the JourneyContext.
const userName = JourneyContext.getValue("user_name");
const favoriteColor = JourneyContext.getValue("favorite_color");

// Compose the greeting and write it back to the JourneyContext.
const greeting = `Hello, ${userName}! Your favourite colour is ${favoriteColor}.`;
JourneyContext.putValue("greeting", greeting);

// Tell the SDK the script finished successfully and the Journey can advance.
onSuccess(true);
Script API in Journeys
  • JourneyContext.getValue("name") reads a value an earlier step wrote.
  • JourneyContext.putValue("name", value) writes a value for later steps to read.
  • A Script step must end by calling onSuccess(true) to advance, or onSuccess(false) to signal failure. There is no return value used by the SDK.
  • async/await is supported — wrap external work in try/catch and call onSuccess(false) from catch.
Scripts can do much more

Script steps run in the SDK's embedded JavaScript engine. They can read MeData via the MeDataService, invoke ML/AI models via the IntelligenceService, and call external APIs via Managed APIs. See Scripts and Managed APIs for the full picture.

Script Editor

[#07] The Script Editor composing the greeting

Screen step — display the greeting

Drag a Screen step before the End step. Double-click to open the Screen Designer and:

  1. Drop a Text (or Rich Text) component onto the canvas.
  2. Set its content to {{greeting}}. The {{...}} syntax embeds a JourneyContext variable.
  3. Drop a Button component, label it Done, and wire it to advance the Journey.

Screen Designer

[#08] Screen Designer displaying the composed greeting

Connect Start → MeData → Question → Script → Screen → End. Save the draft.

Skip rewards and ZPD

For this first Journey, leave Rewards off and don't request any Zero-Party Data. You can come back and turn either on later.