Skip to main content

MeData Service

MeData Service is the core of the Mobile SDK. It collects MeData values from various sources according to the MeData Definitions managed on Orchestrator. Most of other Mobile SDK services are triggered or effected by MeData Service.

info

Mobile SDK performs background network access to fetch MeData Definitions from DataSapien Orchestrator.

Data Vault

MeData collected by Mobile SDK is always stored on user device. Data is stored in a platform encrypted and sandboxed data base that is called the Data Vault. MeData Service provides methods to query and consume stored MeData in Data Vault.

MeData Collection

Mobile SDK collects data from various sources:

  1. Native — MeData Service executes the native code it contains to access mobile device & OS related data. All native MeData are automatically refreshed to their latest values during DataSapien.setup.
  2. Script — MeData Service executes the script authored on Orchestrator during MeData Definition creation.
  3. Question — self reported data in the form of question answers. Mobile SDK provides its own WebView based UI for answering questions — the same rendering used by Journeys. MeData collected inside a Journey is automatically saved to the Data Vault.
  4. Inferred / Provided — computed MeData: existing data is turned into new data on device. The value is calculated by a Script or a Rule and written to the Data Vault with saveMeDataRecord. For example location is a MeData collected from the user; a script or rule derives the city from it and saves it — from that point on city behaves like any other MeData and can be used in Audience targeting.

MeData is what powers the rest of the platform: Audiences are built on MeData values for targeting, and the data a Journey requests as ZPD comes from MeData. The richer the Data Vault, the better the targeting and personalization.

MeData Model

Every MeData has two sides:

  • MeDataDefinition — the definition, authored on the Orchestrator: programmatic name, data type, constraints, category and storage settings.
  • MeData — the user-side data of that definition, stored longitudinally in the Data Vault.

The data itself is hierarchical: MeDataMeDataRecordMeDataValue. MeData holds everything recorded for a definition over time; each MeDataRecord is one entry; each MeDataValue is one value inside that entry.

For example, a multiple-choice favorite_color MeData where the user can pick more than one answer:

MeData → [red, blue], [white], [red] // all entries over time
MeDataRecord → [red, blue] // one entry
MeDataValue → red // one value in the entry

Use Cases

All of the functions below are also available to Scripts, so Journeys and Rules can query and write MeData the same way your host app does.

Working with Definitions

MeData Definitions are synchronized during DataSapien.setup; call syncMeDataDefinitions to synchronize explicitly at any other time.

  • getMeDataDefinitions returns all definitions on the device.
  • getMeDataDefinition(name) returns a single definition by its programmatic name — the name defined on the Orchestrator.
  • getMeDataCategories returns all categories, and getMeDataDefinitionsByCategory(name) the definitions in one category.

Saving Data into the Vault

saveMeDataRecord(name, values) writes a new record for the given definition. values is intentionally loosely typed because a MeData can have different shapes and types:

  • The value must match the definition's data type (STRING, NUMBER, BOOLEAN, DATETIME, LOCATION, ...). If the type does not match — for example the MeData is a NUMBER but a string is sent — the call fails with an error.
  • If the definition is multivalued, an array of values is expected; otherwise a single value is expected and passing an array fails.

How records accumulate is controlled by the definition's storage settings on the Orchestrator:

  • Store Value Count — MeData is longitudinal: new records are appended over time. This setting caps how many records are kept (default 100). When the cap is exceeded, the oldest record is deleted and the new one is added.
  • Store Only If Value Changes — when enabled, the new value is compared with the latest record and saved only if it changed.

A typical data onboarding scenario — your host app already knows something about the user and wants it in the Data Vault so Audiences and Journeys can use it. For example, recording the user's profession: create a MeData on the Orchestrator with type STRING and single value, then:

DataSapien.getMeDataService().saveMeDataRecord(
name: "profession",
values: "computer engineer",
onSuccess: {
},
onError: { error in
}
)

Reading from the Vault

  • getMeDataRecords(name) returns all records of a MeData.
  • getLastMeDataRecord(name) returns the most recent record.

MeData Service Functions

To access MeDataService functions, get its instance from the DataSapien object: DataSapien.getMeDataService().

See the full function list per platform in the MeData Service API Reference.