Skip to content

Kotlin Behavior Events

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

Setup

Within the application's local.properties, the provided API Key should be specified as follows:

MOVABLE_INK_SDK_API_KEY = "XXX"

Also, in the application manifest file the following meta-data tag should be specified within the application tag:

<meta-data
  android:name="com.movableink.inked.API_KEY"
  android:value="${MOVABLE_INK_SDK_API_KEY}"
/>

Lastly, in the Application level gradle file, under the defaultConfig section:

defaultConfig {
    ....
    manifestPlaceholders["MOVABLE_INK_SDK_API_KEY"] = localProperties['MOVABLE_INK_SDK_API_KEY']
    ....
}

After making changes to the gradle file, perform a gradle sync.

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)

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

Identify User 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 sign up. You should call setMIU with the MIU, then call MIClient.identifyUser().

MIClient.identifyUser()

Predefined Events

Category Viewed

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

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

MIClient.categoryViewed(properties) takes a Map type as an argument to describe the category.

MIClient.categoryViewed(
    mapOf(
        "id" to "sci-fi",
        "title" to "Sci-Fi",
        "url" to productUrl.toString()
    )
)

Product Searched

Key Type Description Max
query String, required 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 Map type as an argument to describe the query of the search.

MIClient.productSearched(
    mapOf(
        "query" to "Hyperion",
        "url" to searchResultsUrl.toString()
    )
)

Product Viewed

Key Type Description Max
id String, required 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 List A list 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 Map An open Map 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 Map type as an argument to describe the product.

MIClient.productViewed(
    mapOf(
        "id" to "1",
        "title" to "Hyperion",
        "price" to "15.99",
        "url" to "https://inkrediblebooks.com/hyperion-dan-simmons",
        "categories" to
            listOf(
                mapOf(
                    "id" to "scifi",
                    "title" to "Sci-Fi",
                    "url" to "https://inkrediblebooks.com/categories/scifi"
                ),
                mapOf(
                    "id" to "fiction",
                    "title" to "Fiction",
                    "url" to "https://inkrediblebooks.com/categories/fiction"
                )
            ),
        "meta" to mapOf("pages" to 496)
    )
)

Product Added

Key Type Description Max
id String, required 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 List A list 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 Map An open Map 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 Map type as an argument to describe the product.

MIClient.productAdded(
    mapOf(
        "id" to "1",
        "title" to "Hyperion",
        "price" to "15.99",
        "url" to "https://inkrediblebooks.com/hyperion-dan-simmons",
        "categories" to
            listOf(
                mapOf(
                    "id" to "scifi",
                    "title" to "Sci-Fi",
                    "url" to "https://inkrediblebooks.com/categories/scifi"
                ),
                mapOf(
                    "id" to "fiction",
                    "title" to "Fiction",
                    "url" to "https://inkrediblebooks.com/categories/fiction"
                )
            ),
        "meta" to mapOf("pages" to 496)
    )
)

Product Removed

Key Type Description Max
id String, required 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 List A list 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 Map An open Map 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 Map type as an argument to describe the product.

 MIClient.productRemoved(
    mapOf (
            "id" to "56544",
            "title" to "All-Purpose Cleaning Wipes",
            "price" to "1.99",
            "url" to "https://www.example.com/variants_id/5f08cb918dcc595aa74b0fbc",
            "categories" to listOf(
                mapOf(
                    "id" to "bathroom",
                    "title" to "Bathroom",
                    "url" to "https://example.com/cat/bathroom"
                )
            ),
            "meta" to mapOf(
                "color" to "green"
            )

    )
)

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 List A list of the products in an order. A Product 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 Map type as an argument to describe the order and its items.

MIClient.orderCompleted(
    mapOf(
        "id" to "1",
        "revenue" to "15.99",
        "products" to
            listOf(
                mapOf(
                    "id" to "1",
                    "price" to "15.99",
                    "title" to "Hyperion",
                    "url" to "https://inkrediblebooks.com/hyperion-dan-simmons",
                    "quantity" to 1
                )
            )
    )
)

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.

val properties = mapOf(
  "title" to "Cat Bloopers 1000",
  "tags" to listOf("comedy", "cats"),
  "total" to 14,
  "daily_watched" to listOf(1, 0, 3, 2, 1, 6)
)

MIClient.logEvent("video_started", properties)

Note

Note that the value of price in any predefined event is in dollars and cents such as "15.99".

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.