Skip to content

Behavior Events

The MovableInk SDK allows you to send specific behavior events that can be later used in your Campaigns.

Setup

You'll need an API Key to enable Behavior Events for your app. If you don't already have one, please reach out to your CX Team at MovableInk with your applications bundle identifier.

Once you have an API Key, you can either supply it via the start method:

MIClient.start(apiKey: "MY_API_KEY", deeplinkDomains: ["mi.example.com"]) { result in 

}

or you can add a new key/value pair in your applications Info.plist:

<key>movable_ink_api_key</key>
    <string>YOUR_API_KEY</string>

Setting MIU (mi_u)

An MIU is an identifier used by your companies marketing team and email/mobile messaging provider, that when shared with MovableInk, allows to uniquely identify each of your customers when the interact with campaigns or any other MovableInk content.

Most distribution partners provide a unique user identifier as an available merge tag that distinctly identifies every recipient on your list(s). Using this merge tag allows MovableInk to provide users with a consistent experience when opening the same email multiple times and across multiple devices. Providing an MIU is required for accurate behavior and conversion tracking.

You'll need to work with your distribution partners to identify a unique user identifier. It must meet the following criteria:

You should make the following call as soon as the user is identified (usually after logging in) to set the MIU. Double check with your marketing team that the MIU you're using matches the values they are using. It's imperative that they match for accurate behavior event tracking.

MIClient.setMIU(USERS_MIU)
[MIClient setMIU:USERS_MIU];

Inherited MIUs

If a user interacts with a MovableInk Link that contains an MIU and deeplinks into your app, the SDK will use that MIU value automatically for all subsequent behavior events if you don't manually set an MIU.

If you manually set an MIU, events will use that instead.

Suggested MIU naming convention

We strongly recommend you use a UUID for MIUs.

If you find your ids include names, email addresses, timestamps, or are easily incremental (1, 2, 3), we suggest using a new naming method that is more secure so that your MIUs are not as easy to guess or impersonate.

Recommended NOT Recommended
42772706-c225-43ad-837e-c01e94907c3c user@example.com
d68d3dbe-86e1-43ce-bf5f-2dafd2f6af45 123456789
6ec4f1dd-0998-4ca8-8793-7511c2625a45 john-smith-123

Identify User

The identifyUser method enables the linking of events from an anonymous user to a known user.

If you track events without an MIU being known or set, you can later associate those events to a user once they become known, such as after login.

For example, a user uses the app as a guest and you track events. At some point you prompt the user to sign up, and they do. You should call setMIU with the users MIU, then call MIClient.identifyUser() to notify MovableInk to associate any events that user made as a guest to this account.

MIClient.identifyUser()
[MIClient identifyUser];

Predefined Events

Category Viewed

Key Type Description Max
id String, required, must not be empty The ID of a category 256
title String The title of the category 512
url String The URL of the category 512

When a views a category, you can use the Category Viewed Event.

MIClient.categoryViewed(category:) takes a ProductCategory type as an argument to describe the category.

ProductCategory requires an ID, and optionally other fields.

MIClient.categoryViewed(
  category: .init(
    id: "sci-fi",
    title: "Sci-Fi",
    url: URL(string: "https://inkrediblebooks.com/categories/scifi")
  )
)

Product Searched

Key Type Description Max
query String, required, must not be empty The query the user used for a given search 256
url String A URL for the given query 512

When a user searches for a product, you can use the Product Searched Event.

MIClient.productSearched(properties:) takes a ProductSearchedProperties type as an argument to describe the query of the search.

ProductSearchedProperties requires a query, and optionally other fields.

MIClient.productSearched(
  category: .init(
    query: "Hyperion"
    url: URL(string: "https://inkrediblebooks.com/categories/scifi")
  )
)

Note that this request will be debounced

Product Viewed

Key Type Description Max
id String, required, must not be empty The ID of a product 256
title String The title of the product 512
price String The price of the product in Dollars and Cents
url String The URL of the product 512
categories Array<ProductCategory> An array of categories associated with the product. A category must contain an id (String) and optionally a url (String) and/or title (String) 10 Items
meta Dictionary<String, Any> An open Dictionary of any extra data you'd like to associate to this event 20 Items

When a user views a product in your app, you can use the Product Viewed Event.

MIClient.productViewed(properties:) takes a ProductProperties type as an argument to describe the product.

ProductProperties requires an ID, and optionally other fields.

MIClient.productViewed(
  properties: .init(
    id: "1",
    title: "Hyperion",
    price: "15.99",
    url: URL(string: "https://inkrediblebooks.com/hyperion-dan-simmons")!,
    categories: [
      ProductCategory(id: "Sci-Fi", url: URL(string: "https://inkrediblebooks.com/categories/scifi")!),
      ProductCategory(id: "Fiction", url: URL(string: "https://inkrediblebooks.com/categories/fiction")!)
    ],
    meta: [
      "pages": 496
    ]
  )
)

Note that the price is in dollars and cents. Using a String is recommended. There are overloads for numerical types such as Double or Int which will attempt to convert to a String for you.

For example, if you supply an Int, such as 15, it will be inferred as 15.00.

Product Added

Key Type Description Max
id String, required, must not be empty The ID of a product 256
title String The title of the product 512
price String The price of the product in Dollars and Cents
url String The URL of the product 512
categories Array<ProductCategory> An array of categories associated with the product. A category must contain an id (String) and optionally a url (String) and/or title (String) 10 Items
meta Dictionary<String, Any> An open Dictionary of any extra data you'd like to associate to this event 20 Items

When a user adds a product to the cart in your app, you can use the Product Added Event.

MIClient.productAdded(properties:) takes a ProductProperties type as an argument to describe the product.

ProductProperties requires an ID, and optionally other fields.

MIClient.productAdded(
  properties: .init(
    id: "1",
    title: "Hyperion",
    price: "15.99",
    url: URL(string: "https://inkrediblebooks.com/hyperion-dan-simmons")!,
    categories: [
      ProductCategory(id: "Sci-Fi", url: URL(string: "https://inkrediblebooks.com/categories/scifi")!),
      ProductCategory(id: "Fiction", url: URL(string: "https://inkrediblebooks.com/categories/fiction")!)
    ],
    meta: [
      "pages": 496
    ]
  )
)

Note that the price is in dollars and cents. Using a String is recommended. There are overloads for numerical types such as Double or Int which will attempt to convert to a String for you.

For example, if you supply an Int, such as 15, it will be inferred as 15.00.

Product Removed

Key Type Description Max
id String, required, must not be empty The ID of a product 256
title String The title of the product 512
price String The price of the product in Dollars and Cents
url String The URL of the product 512
categories Array<ProductCategory> An array of categories associated with the product. A category must contain an id (String) and optionally a url (String) and/or title (String) 10 Items
meta Dictionary<String, Any> An open Dictionary of any extra data you'd like to associate to this event 20 Items

When a user removes a product from the cart in your app, you can use the Product Removed Event.

MIClient.productRemoved(properties:) takes a ProductProperties type as an argument to describe the product.

ProductProperties requires an ID, and optionally other fields.

MIClient.productRemoved(
  properties: .init(
    id: "1",
    title: "Hyperion",
    price: "15.99",
    url: URL(string: "https://inkrediblebooks.com/hyperion-dan-simmons")!,
    categories: [
      ProductCategory(id: "Sci-Fi", url: URL(string: "https://inkrediblebooks.com/categories/scifi")!),
      ProductCategory(id: "Fiction", url: URL(string: "https://inkrediblebooks.com/categories/fiction")!)
    ],
    meta: [
      "pages": 496
    ]
  )
)

Note that the price is in dollars and cents. Using a String is recommended. There are overloads for numerical types such as Double or Int which will attempt to convert to a String for you.

For example, if you supply an Int, such as 15, it will be inferred as 15.00.

Order Completed

Key Type Description Max
id String The ID of a order 256
revenue String The total of the order in Dollars and Cents
products Array<OrderCompletedProduct> An of the products in an order. A OrderCompletedProduct must contain an id (String), and optionally a price (String), quantity (Number), title (String), and/or url (String). 100 Items

When a user checks out and completes an order, you can use the Order Completed Event.

MIClient.orderCompleted(properties:) takes a OrderCompletedProperties type as an argument to describe the order and its items.

OrderCompletedProperties requires an ID and a list of products as an OrderCompletedProduct, and optionally other fields.

MIClient.orderCompleted(
  properties: .init(
    id: "1",
    revenue: "15.99",
    products: [
      .init(
        id: "1",
        title: "Hyperion",
        price: "15.99",
        url: URL(string: "https://inkrediblebooks.com/hyperion-dan-simmons")!,
        quantity: 1
      )
    ]
  )
)

Note that the reveune and price is in dollars and cents. Using a String is recommended. There are overloads for numerical types such as Double or Int which will attempt to convert to a String for you.

For example, if you supply an Int, such as 15, it will be inferred as 15.00.

Custom Events

In addition to the pre-defined events we provide, you can log custom events tailored to your business specific requirements. This flexibility enables you to monitor and understand user interactions beyond what our pre-defined events offer.

This type of event has a custom name name, such as video_started, and optional parameters as the payload.

The name and properties of a custom event must first be defined on your companies account. Please reach out to your CX Team at MovableInk to get started with this.

MIClient.logEvent(name: "video_started", properties: ["title": "Cat Bloopers"])

Testing Behavior Events

When you're ready to test an event, you need to set the MIU to a known value. You should let your CX Team know that you're ready to start testing events and give them the MIU that you are going to use before you do so. This will allow them to verify that the events are being sent correctly.

We usually use an empty UUID for testing, such as 00000000-0000-0000-0000-000000000000.

When you send an event, you should see the event logged in the console. If the event was structured correctly, you should see a success message in the console along side the event name.