Skip to main content
The AppDNA SDK integrates with Firebase Cloud Messaging (FCM) to handle push notification token registration, delivery tracking, and tap tracking.

Prerequisites

Before using push notifications, complete the following setup:
  1. Add google-services.json to your app module directory
  2. Enable FCM in your Firebase console
  3. Upload your FCM server key to the AppDNA console under Settings > Push
Push notifications will not work without a valid google-services.json file and a server key uploaded to the AppDNA console.

Token Registration

Set the FCM Token

Register the device push token when it is received from FCM. This is typically done in your FirebaseMessagingService:
import ai.appdna.sdk.AppDNA
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        super.onNewToken(token)
        AppDNA.setPushToken(token)
    }

    override fun onMessageReceived(message: RemoteMessage) {
        super.onMessageReceived(message)
        // Handle message
    }
}
You can also use the alternative method name:
AppDNA.onNewPushToken(token)
Both setPushToken and onNewPushToken perform the same operation. The token registration payload sent to the backend includes: token, platform="android", device_id, app_version, sdk_version, and os_version.

Set Permission Status

Report whether the user has granted push notification permission:
AppDNA.setPushPermission(granted = true)
On Android 13+ (API 33), push notifications require the POST_NOTIFICATIONS runtime permission. Call setPushPermission after the user responds to the permission request.

Delivery and Tap Tracking

Track Delivery

When a push notification is delivered to the device, track it:
AppDNA.trackPushDelivered(pushId = "push-123")

Track Tap

When a user taps a push notification, track the interaction with an optional action identifier:
AppDNA.trackPushTapped(pushId = "push-123", action = "open_workout")
The action parameter is optional. Pass null if no specific action is associated with the tap.

Push Module

The AppDNA.push module (PushModule) provides lower-level access to push functionality:
Method / PropertyDescription
token: String?The currently registered push token
getToken(): String?Returns the current push token
setToken(token: String)Registers the push token
trackDelivered(pushId: String)Tracks push delivery
trackTapped(pushId: String, action: String?)Tracks push tap with optional action
requestPermission()Triggers permission request
setDelegate(delegate: AppDNAPushDelegate?)Sets the push delegate

Push Delegate

Implement AppDNAPushDelegate to receive push lifecycle callbacks:
import ai.appdna.sdk.push.AppDNAPushDelegate
import ai.appdna.sdk.push.PushPayload

class MyPushDelegate : AppDNAPushDelegate {

    override fun onPushTokenRegistered(token: String) {
        Log.d("Push", "Token registered: $token")
    }

    override fun onPushReceived(notification: PushPayload, inForeground: Boolean) {
        Log.d("Push", "Push received: ${notification.title}")
        if (inForeground) {
            // Show in-app notification
        }
    }

    override fun onPushTapped(notification: PushPayload, actionId: String?) {
        Log.d("Push", "Push tapped: ${notification.pushId}, action: $actionId")
        // Navigate to relevant screen
    }
}

// Set the delegate
AppDNA.push.setDelegate(MyPushDelegate())

Data Types

PushPayload

PropertyTypeDescription
pushIdStringUnique identifier for the push
titleStringNotification title
bodyStringNotification body
imageUrlString?Optional image URL
dataMap<String, Any>?Optional custom data payload
actionPushAction?Optional action configuration

PushAction

PropertyTypeDescription
typeStringAction type (e.g., “deep_link”)
valueStringAction value (e.g., a URL)
The SDK automatically handles token refresh. When FCM issues a new token, call setPushToken or onNewPushToken again to update the registration on the AppDNA backend.

Next Steps