Documentation

Developers

API References
Data Subject Request API

Data Subject Request API Version 1 and 2

Data Subject Request API Version 3

Platform API

Platform API Overview

Accounts

Apps

Audiences

Calculated Attributes

Data Points

Feeds

Field Transformations

Services

Users

Workspaces

Warehouse Sync API

Warehouse Sync API Overview

Warehouse Sync API Tutorial

Warehouse Sync API Reference

Data Mapping

Warehouse Sync SQL Reference

Warehouse Sync Troubleshooting Guide

ComposeID

Warehouse Sync API v2 Migration

Bulk Profile Deletion API Reference

Calculated Attributes Seeding API

Custom Access Roles API

Data Planning API

Group Identity API Reference

Pixel Service

Profile API

Events API

mParticle JSON Schema Reference

IDSync

Client SDKs
AMP

AMP SDK

Android

Initialization

Configuration

Network Security Configuration

Event Tracking

User Attributes

IDSync

Screen Events

Commerce Events

Location Tracking

Media

Kits

Application State and Session Management

Data Privacy Controls

Error Tracking

Opt Out

Push Notifications

WebView Integration

Logger

Preventing Blocked HTTP Traffic with CNAME

Linting Data Plans

Troubleshooting the Android SDK

API Reference

Upgrade to Version 5

Cordova

Cordova Plugin

Identity

Flutter

Getting Started

Usage

API Reference

Direct Url Routing

Direct URL Routing FAQ

Web

Android

iOS

iOS

Initialization

Configuration

Event Tracking

User Attributes

IDSync

Screen Tracking

Commerce Events

Location Tracking

Media

Kits

Application State and Session Management

Data Privacy Controls

Error Tracking

Opt Out

Push Notifications

Webview Integration

Upload Frequency

App Extensions

Preventing Blocked HTTP Traffic with CNAME

Linting Data Plans

Troubleshooting iOS SDK

Social Networks

iOS 14 Guide

iOS 15 FAQ

iOS 16 FAQ

iOS 17 FAQ

iOS 18 FAQ

API Reference

Upgrade to Version 7

React Native

Getting Started

Identity

Roku

Getting Started

Identity

Media

Unity

Upload Frequency

Getting Started

Opt Out

Initialize the SDK

Event Tracking

Commerce Tracking

Error Tracking

Screen Tracking

Identity

Location Tracking

Session Management

Xbox

Getting Started

Identity

Web

Initialization

Configuration

Content Security Policy

Event Tracking

User Attributes

IDSync

Page View Tracking

Commerce Events

Location Tracking

Media

Kits

Application State and Session Management

Data Privacy Controls

Error Tracking

Opt Out

Custom Logger

Persistence

Native Web Views

Self-Hosting

Multiple Instances

Web SDK via Google Tag Manager

Preventing Blocked HTTP Traffic with CNAME

Facebook Instant Articles

Troubleshooting the Web SDK

Browser Compatibility

Linting Data Plans

API Reference

Upgrade to Version 2 of the SDK

Xamarin

Getting Started

Identity

Web

Alexa

Server SDKs

Node SDK

Go SDK

Python SDK

Ruby SDK

Java SDK

Quickstart
Android

Overview

Step 1. Create an input

Step 2. Verify your input

Step 3. Set up your output

Step 4. Create a connection

Step 5. Verify your connection

Step 6. Track events

Step 7. Track user data

Step 8. Create a data plan

Step 9. Test your local app

HTTP Quick Start

Step 1. Create an input

Step 2. Create an output

Step 3. Verify output

iOS Quick Start

Overview

Step 1. Create an input

Step 2. Verify your input

Step 3. Set up your output

Step 4. Create a connection

Step 5. Verify your connection

Step 6. Track events

Step 7. Track user data

Step 8. Create a data plan

Java Quick Start

Step 1. Create an input

Step 2. Create an output

Step 3. Verify output

Node Quick Start

Step 1. Create an input

Step 2. Create an output

Step 3. Verify output

Python Quick Start

Step 1. Create an input

Step 2. Create an output

Step 3. Verify output

Web

Overview

Step 1. Create an input

Step 2. Verify your input

Step 3. Set up your output

Step 4. Create a connection

Step 5. Verify your connection

Step 6. Track events

Step 7. Track user data

Step 8. Create a data plan

Tools

mParticle Command Line Interface

Linting Tools

Smartype

Media SDKs

iOS

Web

Android

Guides
Partners

Introduction

Outbound Integrations

Outbound Integrations

Firehose Java SDK

Inbound Integrations

Kit Integrations

Overview

Android Kit Integration

JavaScript Kit Integration

iOS Kit Integration

Compose ID

Data Hosting Locations

Glossary

Rules Developer Guide

Migrate from Segment to mParticle

Migrate from Segment to mParticle

Migrate from Segment to Client-side mParticle

Migrate from Segment to Server-side mParticle

Segment-to-mParticle Migration Reference

API Credential Management

The Developer's Guided Journey to mParticle

Guides

Getting Started

Create an Input

Start capturing data

Connect an Event Output

Create an Audience

Connect an Audience Output

Transform and Enhance Your Data

Platform Guide
The New mParticle Experience

The new mParticle Experience

The Overview Map

Observability

Observability Overview

Observability User Guide

Observability Span Glossary

Introduction

Data Retention

Connections

Activity

Live Stream

Data Filter

Rules

Tiered Events

mParticle Users and Roles

Analytics Free Trial

Troubleshooting mParticle

Usage metering for value-based pricing (VBP)

Analytics

Introduction

Setup

Sync and Activate Analytics User Segments in mParticle

User Segment Activation

Welcome Page Announcements

Settings

Project Settings

Roles and Teammates

Organization Settings

Global Project Filters

Portfolio Analytics

Analytics Data Manager

Analytics Data Manager Overview

Events

Event Properties

User Properties

Revenue Mapping

Export Data

UTM Guide

Query Builder

Data Dictionary

Query Builder Overview

Modify Filters With And/Or Clauses

Query-time Sampling

Query Notes

Filter Where Clauses

Event vs. User Properties

Group By Clauses

Annotations

Cross-tool Compatibility

Apply All for Filter Where Clauses

Date Range and Time Settings Overview

Understanding the Screen View Event

Analyses

Analyses Introduction

Segmentation: Basics

Getting Started

Visualization Options

For Clauses

Date Range and Time Settings

Calculator

Numerical Settings

Segmentation: Advanced

Assisted Analysis

Properties Explorer

Frequency in Segmentation

Trends in Segmentation

Did [not] Perform Clauses

Cumulative vs. Non-Cumulative Analysis in Segmentation

Total Count of vs. Users Who Performed

Save Your Segmentation Analysis

Export Results in Segmentation

Explore Users from Segmentation

Funnels: Basics

Getting Started with Funnels

Group By Settings

Conversion Window

Tracking Properties

Date Range and Time Settings

Visualization Options

Interpreting a Funnel Analysis

Funnels: Advanced

Group By

Filters

Conversion over Time

Conversion Order

Trends

Funnel Direction

Multi-path Funnels

Analyze as Cohort from Funnel

Save a Funnel Analysis

Explore Users from a Funnel

Export Results from a Funnel

Cohorts

Getting Started with Cohorts

Analysis Modes

Save a Cohort Analysis

Export Results

Explore Users

Saved Analyses

Manage Analyses in Dashboards

Journeys

Getting Started

Event Menu

Visualization

Ending Event

Save a Journey Analysis

Users

Getting Started

User Activity Timelines

Time Settings

Export Results

Save A User Analysis

Dashboards

Dashboards––Getting Started

Manage Dashboards

Dashboard Filters

Organize Dashboards

Scheduled Reports

Favorites

Time and Interval Settings in Dashboards

Query Notes in Dashboards

User Aliasing

Analytics Resources

The Demo Environment

Keyboard Shortcuts

Tutorials

Analytics for Marketers

Analytics for Product Managers

Compare Conversion Across Acquisition Sources

Analyze Product Feature Usage

Identify Points of User Friction

Time-based Subscription Analysis

Dashboard Tips and Tricks

Understand Product Stickiness

Optimize User Flow with A/B Testing

User Segments

APIs

User Segments Export API

Dashboard Filter API

IDSync

IDSync Overview

Use Cases for IDSync

Components of IDSync

Store and Organize User Data

Identify Users

Default IDSync Configuration

Profile Conversion Strategy

Profile Link Strategy

Profile Isolation Strategy

Best Match Strategy

Aliasing

Data Master
Group Identity

Overview

Create and Manage Group Definitions

Introduction

Catalog

Live Stream

Data Plans

Data Plans

Blocked Data Backfill Guide

Personalization
Predictive Attributes

Predictive Attributes Overview

Create Predictive Attributes

Assess and Troubleshoot Predictions

Use Predictive Attributes in Campaigns

Predictive Audiences

Predictive Audiences Overview

Using Predictive Audiences

Introduction

Profiles

Calculated Attributes

Calculated Attributes Overview

Using Calculated Attributes

Create with AI Assistance

Calculated Attributes Reference

Audiences

Audiences Overview

Real-time Audiences

Standard Audiences

Journeys

Journeys Overview

Manage Journeys

Download an audience from a journey

Audience A/B testing from a journey

Journeys 2.0

Warehouse Sync

Data Privacy Controls

Data Subject Requests

Default Service Limits

Feeds

Cross-Account Audience Sharing

Approved Sub-Processors

Import Data with CSV Files

Import Data with CSV Files

CSV File Reference

Glossary

Video Index

Analytics (Deprecated)
Identity Providers

Single Sign-On (SSO)

Setup Examples

Settings

Debug Console

Data Warehouse Delay Alerting

Introduction

Developer Docs

Introduction

Integrations

Introduction

Rudderstack

Google Tag Manager

Segment

Data Warehouses and Data Lakes

Advanced Data Warehouse Settings

AWS Kinesis (Snowplow)

AWS Redshift (Define Your Own Schema)

AWS S3 (Snowplow Schema)

AWS S3 Integration (Define Your Own Schema)

BigQuery (Snowplow Schema)

BigQuery Firebase Schema

BigQuery (Define Your Own Schema)

GCP BigQuery Export

Snowflake (Snowplow Schema)

Snowplow Schema Overview

Snowflake (Define Your Own Schema)

APIs

REST API

Dashboard Filter API (Deprecated)

User Segments Export API (Deprecated)

SDKs

SDKs Introduction

React Native

iOS

Android

Java

JavaScript

Python

Object API

Developer Basics

Aliasing

Smartype

Overview

Smartype is a powerful code generation tool, built for mParticle’s Data Master, that allows you to turn your Data Plans into useable, type-safe code.

It aims to completely eliminate an entire class of data quality bugs 🐛 by generating statically-typed data models based on the popular JSON schema standard.

  • Smartype is built to translate mParticle Data Plans into type-safe models
  • It gives you auto-complete for your data model in your IDE of choice
  • It’s open source and extensible via a plugin system

Example

The following JSON schema describes a coffee order with a few required parameters:

  • item: An string value with a predefined set of allowed values
  • quantity: A numeric value indicating how many coffees were ordered
  • milk: A boolean value indicating if you want milk in your coffee

Smartype does the following with this:

  • Consumes the JSON schema and generates Kotlin data classes
  • Uses Kotlin Multiplatform to translate that Kotlin code into other languages and generate consumable binaries
  • Surfaces an API to send and receive these “messages”, which can be consumed by any analytics provider or your own system

Supported SDKs

Smartype supports the following SDKs and language environments today:

  1. Any JVM environment:

  2. mParticle Apple SDK
  3. Web browsers and React Native via TypeScript and JavaScript

mParticle Data Plans

Smartype is designed to work with mParticle Data Plans. If you haven’t yet created a Data Plan, you’ll need to do so and download your data plan to work with Smartype.

Create a Data Plan

Download a Data Plan

Once you’ve created your Data Plan(s), we suggest you download them and commit them to source control. That way you can generate Smartype models in your CI system and development environment.

There are a few ways to acquire a data plan:

Workflow

Smartype is shipped as a CLI tool, and so your typical workflow could be:

  1. Programmatically or manually download your data plan
  2. Run Smartype to generate your libraries
  3. Incorporate and use those libraries in any number of environments

Using the mParticle CLI Tool to Download the Data Plan

Rather than manually creating a JSON file, mParticle provides these files ready for use by Smartype. There are multiple ways to retrieve them, but for automation purposes using the mParticle CLI tool is the best option.

We provide a ready-to-use Github Actions workflow file here, which can be adapted to other CI systems: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/data-plan-fetch.yml

Individual developers can also manually download the Data Plan JSON by using the mParticle CLI directly from the command line.

Install the mParticle CLI tool

  1. Install Node using your preferred method for your platform.
  2. Install the mParticle CLI tool: npm install -g @mparticle/cli.

Download the Data Plan JSON

Once the mParticle CLI has been installed, the Data Plan JSON can be downloaded using a single command.

First you will need the following pieces of information:

  • Data Plan ID
  • Data Plan Version
  • Workspace ID
  • Client ID (mParticle access token)
  • Client Secret (mParticle access token)

You can create and manage your mParticle access tokens for Data Planning with the API Credentials interface.

# Here we'll use environment variables, but you can simply pass the values directly to the mp command if you'd prefer
export $DATA_PLAN_ID=...
export $DATA_PLAN_VERSION=...
export $WORKSPACE_ID=...
export $CLIENT_ID=...
export $CLIENT_SECRET=...
# $OUT_FILE can be any file name you like
export $OUT_FILE=${DATA_PLAN_ID}_${DATA_PLAN_VERSION}.json

# Pull down the JSON file
mp planning:data-plan-versions:fetch --dataPlanId=$DATA_PLAN_ID --versionNumber=$DATA_PLAN_VERSION --workspaceId=$WORKSPACE_ID --clientId=$CLIENT_ID --clientSecret=$CLIENT_SECRET --outFile=$OUT_FILE

Getting Started

Smartype is deployed as an executable Java-based CLI. It has several commands which are documented in the sections below.

Download the CLI

Via NPM

You can use mvnx to automate the download and execution of Smartype:

# First install the mvnx package, which downloads and runs jar executables from Maven Central
npm install -g mvnx
# Then run either init or generate directly
mvnx com.mparticle:smartype-generator init

Direct Download

You can also download the latest release from the Github releases page, and then execute it:

java -jar smartype-generator.jar

Requirements

You will need to ensure that a Java SDK is available on your PATH, you can do this by:

  1. If you don’t have one installed, download the free JDK
  2. Set your JAVA_HOME environment variable via export JAVA_HOME=~/path/to/jdk/home replacing the path with the home directory of the downloaded JDK (or an existing JDK already present in your environment)

CLI Commands

The CLI provides two key commands:

  • init: Initialize a configuration file that’s used by Smartype to generate code.
  • generate: Generates strongly-type libraries based on your data model

Smartype init

Smartype init will ask you a series of questions and then create a Smartype configuration file.

When choosing a folder for Smartype files to be written to, as part of the generate step, be sure to create a new folder specific to Smartype so the new files don’t pollute existing folders.

# With mvnx:
mvnx com.mparticle:smartype-generator init

# Or directly execute the pre-downloaded jar
java -jar smartype-generator-[version].jar init

Smartype generate

Smartype generate will read your configuration file and output binaries that are ready for consumption in an application.

# With mvnx:
mvnx com.mparticle:smartype-generator generate

# Or directly execute the pre-downloaded jar
java -jar smartype-generator-[version].jar generate

Integrating Generated Code

To use the objects created by Smartype, you’ll want to add the generated code to your projects. You will also want to initialize Smartype when the app starts up, and register any receivers that you would like to get notified for each message that gets logged.

The following code snippets use the mParticle receiver as an example, but receivers can be created to wrap any interface to which you want to send data, including for your own inhouse processing.

iOS

Requirements

Smartype requires Xcode and Carthage to be installed.

1. Run generate

The following command will generate an iOS “fat” framework containing all architectures. You can customize the output directory of the framework via Smartype init

# With mvnx:
mvnx com:mparticle:smartype-generator generate

# Or directly execute the pre-downloaded jar
java -jar smartype-generator-[version].jar generate

2. Add the Framework

Smartype generate will create a “fat” dynamic framework that you can include directly with your projects. To use Smartype on iOS, start by adding Smartype.framework to your Xcode project

3. Implement the API

  • Import and initialize Smartype prior to use, and register any receivers.
  • The SmartypeApi object will surface a series of methods which each represent the top-level items in your schema
  • Pass the fully constructed objects into your SmartypeApi instance for all receivers
import Smartype

...


let api = SmartypeApi(receivers: [MParticleReceiver(), self])

let options = MParticleOptions.init(
            key: "REPLACE WITH KEY",
            secret: "REPLACE WITH SECRET")
//SmartypeApi surfaces the data plan ID and version of the underlying models
options.dataPlanId = api.dataPlanId
options.dataPlanVersion = api.dataPlanVersion as NSNumber

let chooseCustomAttributes = ChooseItemDataCustomAttributes
    .init(quantity: 5,
          milk: true,
          item: .cortado
)
let itemData = ChooseItemData.init(customAttributes: chooseCustomAttributes)

//Smartype surfaces all mParticle "Data Points" as factory methods
let chooseItem = api.chooseItem(data: itemData)
api.send(message: chooseItem)

Android

For Android apps, Smartype generate will create an aar file that you can include directly with your projects.

Requirements

To generate an Android library, set your ANDROID_SDK_ROOT environment variable via export ANDROID_SDK_ROOT=/Users/<REPLACE>/Library/Android/sdk replacing the path with your user directory or to wherever an Android SDK is available on your machine

1. Run generate

The following command will generate an aar. You can customize the output directory of the aar via Smartype init

# With mvnx:
mvnx com:mparticle:smartype-generator generate

# Or directly execute the pre-downloaded jar
java -jar smartype-generator-[version].jar generate

2. Add dependencies

  • Start by adding the generated smartype.aar to your project
  • Add the com.mparticle:smartype-mparticle receiver Maven Central dependency
dependencies {
    //include the generated aar in your project
    implementation fileTree(dir: 'libs', include: ['**/*.aar'])
    //add the mParticle receiver, which will automatically pull in mParticle as a dependency
    implementation "com.mparticle:smartype-mparticle:1.0.2"
}

3. Implement the API

  • Import and initialize Smartype prior to use, and register your receivers
  • The SmartypeApi object will surface a series of methods which each represent the top-level items in your schema
  • Pass the fully constructed objects into your SmartypeApi instance for all receivers
val api = SmartypeApi(listOf(MParticleReceiver(), this))

val options = MParticleOptions.builder(this)
    .credentials("REPLACE WITH KEY", "REPLACE WITH SECRET")
    //SmartypeApi surfaces the data plan ID and version of the underlying models
    .dataplan(api.dataPlanId, api.dataPlanVersion)
    .build()

val message = api.chooseItem(
    ChooseItemData(
        ChooseItemDataCustomAttributes(
            quantity = 5.0,
            milk = true,
            item = ChooseItemDataCustomAttributesItem.CORTADO
        )
    )
)
//the message object will now be sent to mParticle's SDK
api.send(message)

Web

Smartype generate will create a set of .js and .d.ts files that you can include directly with your projects. Our example uses webpack to concatenate and minify the source files.

To use Smartype on Web, start by adding the generated smartype-dist directory to your project and any 3rd-party receivers that you plan on using, then include the relevant files in your typescript or javascript sources:

import * as kotlin from "../smartype-dist/kotlin.js"
import * as smartype from "../smartype-dist/smartype-smartype.js"
import * as smartypeMparticle from "../smartype-dist/smartype-smartype-mparticle.js"

// create namespace references for easier access
var api = smartype.com.mparticle.smartype
var receivers = smartypeMparticle.com.mparticle.smartype.api.receivers
  • Import and initialize Smartype prior to use, and register your receivers
  • The SmartypeApi object will surface a series of methods which each represent the top-level items in your schema
  • Pass the fully constructed objects into your SmartypeApi instance for all receivers
var smartypeApi = new api.SmartypeApi()
smartypeApi.addReceiver(new receivers.mparticle.MParticleReceiver())
smartypeApi.addReceiver(this)

var message = smartypeApi.chooseItem(
      new api.ChooseItemData(
        new api.ChooseItemDataCustomAttributes(
          1, true, new api.ChooseItemDataCustomAttributesItem().REGULARCOFFEE()
        )
      )
    )

//the message object will now be sent to all receivers
api.send(message)

React Native

In order to enable React Native:

import MParticle from 'react-native-mparticle'

...

var api = new smartype.SmartypeApi()
var receiver = smartype.mParticleReceiver()
receiver.react = MParticle
api.addReceiver(receiver)

You will also want to exclude the generated .smartype directory from your React Project by configuring your metro.config.js file:

const exclusionList = require('metro-config/src/defaults/exclusionList');

... 

module.exports = {
  resolver: {
      blockList: exclusionList([/\.smartype\/.*/])
    },
};

Source Code and Example Projects

Feedback and Questions

Smartype is in a Beta release and we need your help to make it better. For any questions or feedback, please send a note to developers@mparticle.com

Was this page helpful?

    Last Updated: November 12, 2024