Skip to content

Push Notification Analytics

The MovableInk SDK provides automatic tracking for push notification opens. This allows you to measure engagement and attribute conversions to your push campaigns.

Prerequisites

This guide assumes you have already set up Firebase Cloud Messaging (FCM) in your Android app. If you haven't, please refer to the Firebase documentation to set up push notifications first.

Setup

Call MIClient.handlePushNotificationOpened() when a user taps a push notification to allow the SDK to check if it is a MovableInk notification and track the open event.

Kotlin Implementation

In your main Activity, handle the notification tap in both onCreate (for cold starts) and onNewIntent (for warm starts):

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import com.movableink.inked.MIClient

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Check if app was opened from a notification
        checkIntentExtras()

        // Your app setup
        setContent {
            YourApp()
        }
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        this.intent = intent
        checkIntentExtras()
    }

    private fun checkIntentExtras() {
        intent?.extras?.let { bundle ->
            // Optional: Log extras for debugging
            for (key in bundle.keySet()) {
                bundle.getString(key)?.let { value ->
                    Log.d("MovableInk", "Intent Extra - Key: $key, Value: $value")
                }
            }

            // Track the notification open with MovableInk
            MIClient.handlePushNotificationOpened(bundle)
        }
    }
}

Manual Tracking | Without SDK

If you're not using the SDK, you can still track this event by manually making a request to the URL in the payload.

import android.os.Bundle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URL

private fun checkIntentExtras() {
    intent?.extras?.let { bundle ->
        trackMovableInkNotification(bundle)
    }
}

private fun trackMovableInkNotification(bundle: Bundle) {
    // Extract the MovableInk tracking URL from the payload
    val miUrl = bundle.getString("mi_url")

    if (!miUrl.isNullOrEmpty()) {
        CoroutineScope(Dispatchers.IO).launch {
            try {
                URL(miUrl).openConnection().apply {
                    connect()
                    getInputStream().close()
                }
            } catch (e: Exception) {
                // Handle error
            }
        }
    }
}

Payload Format

MovableInk push notifications sent via FCM will have the following payload structure:

{
  "notification": {
    "title": "Special Offer Just for You!",
    "body": "Open to unlock exclusive savings."
  },
  "data": {
    "mi_url": "https://mi.example.com/deeplink/abc123",
    "mi_source": "davinci"
  }
}

The mi_url in the data object is the tracking URL that the SDK uses to record the notification open event.