Mobile Push is currently in beta. Features, APIs, and implementation details may change before general availability.
This guide provides implementation requirements for integrating Engage Studio Mobile Push notifications in your Android app using the Treasure Data Android SDK. Your development team must implement the following functionality:
- FCM Integration: Receive push notifications via Firebase Cloud Messaging
- Token Management: Register and update device tokens with Treasure Data
- Notification Display: Show notifications with images, action buttons, and deep links
- Event Tracking: Track user interactions (delivery, open, dismiss, links) using Treasure Data SDK
- Automated Data Upload: Treasure Data SDK automatically handles event upload to Treasure Data
A complete, production-ready sample application is available on GitHub:
Treasure Data Mobile Push - Android Sample
The sample includes:
- Complete Firebase Messaging Service implementation
- Event tracking with Treasure Data SDK
- Deep link and web link handling
- Notification UI with action buttons and images
Clone the repository and use it as a reference for your implementation.
| Component | Requirement |
|---|---|
| Minimum Android Version | Android 8.0 (API 26) or later |
| Language | Kotlin (recommended) or Java |
| Required Dependencies |
|
| Tracked Events | delivery, open, dismiss, deeplink_open, link_open, token_register |
┌─────────────────────┐
│ Engage Studio │
│ Campaign │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Firebase Cloud │
│ Messaging (FCM) │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Your Android App │
├─────────────────────┤
│ MyFirebaseMessaging │ ← Receives notifications
│ Service │
├─────────────────────┤
│ PushEventReceiver │ ← Handles user actions
├─────────────────────┤
│ Treasure Data SDK │ ← Tracks and uploads events
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ Treasure Data │
│ Ingest API │
└─────────────────────┘Your Android app must implement the following components:
Purpose: Initialize Treasure Data SDK and configure app-wide settings
Key Responsibilities:
- Initialize Treasure Data SDK with API endpoint and database configuration
- Configure automatic data collection settings
- Enable debug logging (optional)
Reference: See MyApplication.kt in the sample repository
Purpose: Receive and display push notifications from FCM
Key Responsibilities:
- Listen for incoming FCM messages
- Extract notification payload (title, body, image, links)
- Display notification with action buttons
- Track
deliveryevents using Treasure Data SDK when notification is received - Handle FCM token updates
Reference: See MyFirebaseMessagingService.kt in the sample repository
Purpose: Handle user interactions with notifications
Key Responsibilities:
- Handle notification tap (main content)
- Handle action button taps (web link, deep link)
- Handle notification dismiss
- Track corresponding events (
open,dismiss,link_open,deeplink_open) using Treasure Data SDK - Open web URLs using Chrome Custom Tabs
- Open deep links within the app
Reference: See PushEventReceiver.kt in the sample repository
Purpose: Manage device token registration with Treasure Data
Key Responsibilities:
- Obtain current FCM token
- Register token with Treasure Data when app launches using SDK
- Re-register token when it's refreshed by FCM
- Associate token with user ID when user logs in
- Track
token_registerevents
Reference: See FcmTokenService.kt in the sample repository
Purpose: Handle notification taps and deep links
Key Responsibilities:
- Receive notification tap intents
- Track
openevents using Treasure Data SDK - Navigate to appropriate screen based on deep link
- Open web URLs when specified
Reference: See MainActivity.kt in the sample repository
Your app will receive the following JSON structure in the FCM data payload:
{
"td_campaign_id": "cmp_20251214_promo",
"title": "Special Offer!",
"body": "Get 20% off your next purchase",
"image_url": "https://cdn.example.com/banner.png",
"link": "https://example.com/promo"
}| Field | Type | Required | Description |
|---|---|---|---|
td_campaign_id | String | Yes | Unique campaign identifier from Engage Studio |
title | String | Yes | Notification title |
body | String | Yes | Notification body text |
image_url | String | No | URL for rich notification image |
link | String | No | Web URL to open in browser |
Your app must track the following events and send them to Treasure Data:
| Event Type | When to Track | Required Fields |
|---|---|---|
delivery | When notification is received and displayed | campaign_id, platform, time |
open | When user taps the notification | campaign_id, platform, time, user_id |
dismiss | When user dismisses the notification | campaign_id, platform, time, user_id |
link_open | When user taps a web link | campaign_id, platform, time, user_id, value (URL) |
deeplink_open | When user taps a deep link | campaign_id, platform, time, user_id, value (URI) |
token_register | When FCM token is obtained or refreshed | fcm_token, platform, time, user_id (if logged in) |
All events are automatically sent by the Treasure Data SDK to the configured Treasure Data endpoint. The SDK handles batching, queuing, and retry logic automatically.
See the Push Events Table documentation for complete schema details.
Your app must declare:
INTERNETpermissionPOST_NOTIFICATIONSpermission (Android 13+)- Firebase Messaging Service
- Broadcast Receiver for notification actions
- Deep link intent filters
Required dependencies:
- Firebase BoM:
34.7.0or later - Firebase Messaging (version managed by BoM)
- Treasure Data Android SDK:
1.1.0or later - WorkManager:
2.9.1or later - Chrome Custom Tabs:
1.8.0or later
Example dependency configuration:
dependencies {
// Firebase
implementation(platform("com.google.firebase:firebase-bom:34.7.0"))
implementation("com.google.firebase:firebase-messaging")
implementation("com.google.firebase:firebase-analytics")
// Treasure Data SDK
implementation("com.treasuredata:td-android-sdk:1.1.0")
// Background tasks
implementation("androidx.work:work-runtime-ktx:2.9.1")
// Web links
implementation("androidx.browser:browser:1.8.0")
}Configure Treasure Data settings in local.properties (this file should be excluded from version control):
TD_WRITE_KEY=your_write_api_key_here
TD_DATABASE=mobile
TD_TABLE=push_events
TD_ENDPOINT=https://in.treasuredata.comAccess these properties in your build.gradle.kts:
val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))
android {
defaultConfig {
buildConfigField("String", "TD_WRITE_KEY", "\"${localProperties["TD_WRITE_KEY"]}\"")
buildConfigField("String", "TD_DATABASE", "\"${localProperties["TD_DATABASE"]}\"")
buildConfigField("String", "TD_TABLE", "\"${localProperties["TD_TABLE"]}\"")
buildConfigField("String", "TD_ENDPOINT", "\"${localProperties["TD_ENDPOINT"]}\"")
}
}For Android 13+ (API 33), request POST_NOTIFICATIONS permission at runtime.
To link push notification events with specific users:
- Logged-in users: Include
user_id(e.g., customer ID, email hash) in all events - Anonymous users: Pass
nullforuser_idin events - On login: Send new
token_registerevent withuser_idto associate the device
Treasure Data will link all previous events from the same fcm_token to the user.
- Run your app on a device with Google Play Services
- Check logcat for FCM token
- Send test notification from Firebase Console
- Verify notification appears on device
Query Treasure Data to confirm events are being logged:
SELECT
time,
type,
campaign_id,
platform
FROM mobile.push_events
WHERE platform = 'android'
ORDER BY time DESC
LIMIT 100API Keys:
- Never commit
local.propertiesto source control - Add
local.propertiesto.gitignore - Use write-only keys (not master keys)
- Store sensitive configuration in
local.properties, not in code
- Never commit
Deep Links:
- Always validate deep link destinations
- Implement URL allowlists for sensitive actions
- Sanitize parameters before navigation
Event Data:
- Do not include PII in event payloads
- Use hashed or anonymized user IDs when possible
Network Security:
- Always use HTTPS for API endpoints
- Consider certificate pinning for production
- Verify FCM token is generated and uploaded
- Check Google Play Services is installed and updated
- Verify notification permissions (Android 13+)
- Check
google-services.jsonis inapp/directory
- Verify
TD_WRITE_KEYinlocal.propertiesis correct - Check
TD_ENDPOINTmatches your region - Verify database and table exist in Treasure Data
- Check Treasure Data SDK is properly initialized in
MyApplication - Enable debug logging to see SDK activity:
TreasureData.enableLogging()
- Verify intent filter in AndroidManifest.xml
- Test with:
adb shell am start -W -a android.intent.action.VIEW -d "myapp://test" - Check URI format matches registered scheme
Complete, production-ready implementation:
https://github.com/treasure-data/engage-push-notification-sample/tree/main/android
The repository includes:
- Full source code with inline documentation
- Gradle configuration with Treasure Data SDK integration
- AndroidManifest.xml setup
- Testing instructions
- Security best practices
- Example configuration files
This section provides detailed instructions for building and testing the sample application.
The sample repository follows this directory structure:
android/
├── app/
│ ├── src/main/
│ │ ├── java/com/treasuredata/pushsample/
│ │ │ ├── MainActivity.kt # Deep link and notification handling
│ │ │ ├── MyApplication.kt # App initialization & TD SDK setup
│ │ │ ├── CategoryActivity.kt # Category view example
│ │ │ ├── ProductDetailActivity.kt # Product detail example
│ │ │ ├── fcm/
│ │ │ │ ├── MyFirebaseMessagingService.kt # FCM message receiver
│ │ │ │ ├── PushEventReceiver.kt # Notification action handler
│ │ │ │ ├── PushAction.kt # Action constants
│ │ │ │ └── FcmTokenService.kt # Token management
│ │ │ └── utils/ # Utility classes
│ │ ├── res/
│ │ │ ├── layout/
│ │ │ ├── drawable/
│ │ │ └── values/
│ │ └── AndroidManifest.xml
│ ├── build.gradle.kts
│ └── google-services.json.example # Firebase config template
├── gradle/
├── build.gradle.kts
├── local.properties.example # TD configuration template
└── settings.gradle.kts- Android Studio Hedgehog (2023.1.1) or later
- JDK 17 or later
- Android SDK 26 (Android 8.0) or later
- Clone the repository:
git clone https://github.com/treasure-data/engage-push-notification-sample.git
cd engage-push-notification-sample/android- Open project in Android Studio:
# Open Android Studio and select "Open an Existing Project"
# Navigate to the android/ directoryConfigure Firebase:
- Download
google-services.jsonfrom your Firebase project - Copy it to
app/google-services.json - Update
applicationIdinapp/build.gradle.ktsto match your Firebase app
- Download
Configure Treasure Data:
- Copy
local.properties.exampletolocal.properties - Edit
local.propertieswith your Treasure Data configuration:
TD_WRITE_KEY=your_write_api_key_here TD_DATABASE=mobile TD_TABLE=push_events TD_ENDPOINT=https://in.treasuredata.com- Important: Do not commit
local.propertiesto version control
- Copy
Sync Gradle:
- Click "Sync Now" when prompted
- Or File > Sync Project with Gradle Files
Build and run:
# Via Gradle command line
./gradlew assembleDebug
# Or use Android Studio Run button (Shift+F10)Before testing, ensure you have:
- Firebase project with Android app registered
-
google-services.jsondownloaded and placed inapp/directory - Treasure Data database and table created
- Write-only API key obtained
- Android emulator or physical device with Google Play Services
- Create/start Android emulator:
# List available emulators
emulator -list-avds
# Start emulator
emulator -avd Pixel_5_API_34- Install and run app:
./gradlew installDebug
adb shell am start -n com.treasuredata.pushsample/.MainActivity- Monitor logs for FCM token:
adb logcat | grep -E "FCM token|FCMService"Expected output:
I/FcmTokenService: FCM token: [your-device-token]
I/FcmTokenService: Registering FCM token: [token]Send test notification from Firebase Console:
- Open Firebase Console > Cloud Messaging
- Click "Send your first message"
- Enter title: "Test Notification"
- Enter body: "This is a test"
- Click "Send test message"
- Paste your FCM token
- Click "Test"
Verify notification appears in system tray
Tap notification and verify:
- App opens (if closed)
openevent is tracked- Deep link navigates correctly (if configured)
Enable Developer Options:
- Settings > About phone > Tap "Build number" 7 times
Enable USB Debugging:
- Settings > System > Developer options > USB debugging
Connect device via USB and install:
# Verify device is connected
adb devices
# Install app
./gradlew installDebug
# Launch app
adb shell am start -n com.treasuredata.pushsample/.MainActivity- Follow steps 3-6 from emulator testing above
Create test payload with actions in Firebase Console:
- Add custom data fields:
campaign_id:test_campaign_001message_id:msg_001deeplink:myapp://product/12345link:https://example.com/promo
- Add custom data fields:
Send notification and test:
- Tap notification body → Verify
openevent - Tap web link → Verify Chrome Custom Tab opens
- Tap deep link → Verify app navigation
- Dismiss notification → Verify
dismissevent
- Tap notification body → Verify
Query Treasure Data to confirm events are being logged:
SELECT
time,
type,
campaign_id,
platform,
user_id,
value
FROM mobile.push_events
WHERE platform = 'android'
AND time > td_time_add(now(), '-1h', 'JST')
ORDER BY time DESC
LIMIT 20Expected event sequence:
token_register- When app launchesdelivery- When notification is receivedopen- When user taps notificationlink_open- When user taps web linkdeeplink_open- When user taps deep linkdismiss- When user dismisses notification
Test deep link handling using ADB:
# Test product deep link
adb shell am start \
-W -a android.intent.action.VIEW \
-d "myapp://product/12345" \
com.treasuredata.pushsample
# Test category deep link
adb shell am start \
-W -a android.intent.action.VIEW \
-d "myapp://category/electronics" \
com.treasuredata.pushsampleVerify app opens and navigates to correct screen.
Use this checklist when implementing push notifications in your own app:
- Create Android project with minimum SDK 26 (Android 8.0)
- Add Firebase dependencies in
build.gradle.kts - Add WorkManager, OkHttp, Chrome Custom Tabs dependencies
- Download and add
google-services.jsontoapp/directory - Apply
com.google.gms.google-servicesplugin - Add required permissions in AndroidManifest.xml
- Declare
INTERNETpermission - Declare
POST_NOTIFICATIONSpermission (Android 13+) - Register
MyFirebaseMessagingServicein manifest - Register
PushEventReceiverbroadcast receiver - Add intent filter for deep links in MainActivity
- Configure notification channels (Android 8+)
- Create
MyApplicationclass for app initialization - Initialize Firebase in
onCreate - Initialize Treasure Data SDK with endpoint, database, and API key
- Configure TD SDK auto-tracking features (optional)
- Implement
MyFirebaseMessagingService - Implement
onMessageReceivedto handle FCM messages - Implement
onNewTokento handle token refresh - Create
FcmTokenServicefor token management
- Create notification channel with importance level
- Build notification with title, body, icon
- Add PendingIntent for notification tap
- Add PendingIntent for notification dismiss
- Download and attach images (if
image_urlpresent) - Add action buttons for links (if configured)
- Show notification with NotificationManager
- Track
deliveryevent inonMessageReceivedusing TD SDK - Track
openevent when notification is tapped using TD SDK - Track
dismissevent when notification is dismissed using TD SDK - Track
link_openevent for web link taps using TD SDK - Track
deeplink_openevent for app link taps using TD SDK - Track
token_registerevent on app launch and token refresh using TD SDK
- Create
PushEventReceiverto handle broadcast intents - Handle
PUSH_OPENaction in receiver - Handle
PUSH_DISMISSaction in receiver - Handle
PUSH_ACTION_LINKaction in receiver - Handle
PUSH_ACTION_DEEPLINKaction in receiver - Open Chrome Custom Tab for web links
- Parse and navigate deep links in MainActivity
- Create
local.propertieswith TD configuration - Add
local.propertiesto.gitignore - Add
google-services.jsonto.gitignore - Configure BuildConfig fields from
local.properties - Implement error handling for TD SDK operations
- Add ProGuard rules for Treasure Data SDK if using R8/ProGuard
- Request
POST_NOTIFICATIONSpermission at runtime (Android 13+) - Test notification delivery on emulator
- Test notification delivery on physical device
- Test notification images
- Test notification action buttons
- Test deep link navigation
- Test web link opening with Chrome Custom Tabs
- Verify events appear in Treasure Data
- Test background notification handling
- Test foreground notification handling
# Ensure file is in correct location
ls app/google-services.json
# Sync Gradle files
./gradlew --refresh-dependencies- Check for duplicate permissions or activities in AndroidManifest.xml
- Verify all library versions are compatible
- Run
./gradlew cleanand rebuild
# Check SDK initialization logs
adb logcat | grep TreasureData
# Enable debug logging in MyApplication.kt:
TreasureData.enableLogging()
# Verify BuildConfig values are set correctly
# Check build/generated/source/buildConfig/debug/.../BuildConfig.java- Verify Google Play Services is installed on device/emulator
- Check notification permission is granted (Android 13+)
- Verify notification channel is created with correct importance
- Check logcat for FCM errors:
adb logcat | grep FCM
- Verify
TD_WRITE_KEYinlocal.propertiesis correct - Check network connectivity
- Verify
TD_ENDPOINTmatches your region - Check Treasure Data SDK logs:
adb logcat | grep TreasureData - Verify SDK is initialized correctly in
MyApplication.onCreate() - Try calling
TreasureData.sharedInstance().uploadEvents()manually to force upload
# Verify intent filter is registered
adb shell dumpsys package com.treasuredata.pushsample | grep -A 5 "scheme"
# Test deep link manually
adb shell am start -W -a android.intent.action.VIEW -d "myapp://test"# Clean build
./gradlew clean
# Build debug APK
./gradlew assembleDebug
# Build release APK (requires signing config)
./gradlew assembleRelease
# Install on connected device
./gradlew installDebug
# Run unit tests
./gradlew testDebugUnitTest
# Run instrumented tests
./gradlew connectedDebugAndroidTest
# Check for dependency updates
./gradlew dependencyUpdates
# Lint check
./gradlew lintDebug
# Generate dependency tree
./gradlew app:dependencies- Clone the sample repository and review the implementation
- Configure Firebase following the Mobile Push Setup guide
- Implement the components in your Android app
- Test notification delivery and event tracking
- Review event data in the Push Events Table
- Create your first campaign in Engage Studio
- Mobile Push Setup - Firebase and Treasure Data configuration
- iOS Developer Guide - iOS implementation guide
- Push Events Table - Event schema and analytics queries
- Campaign Creation - Create Mobile Push campaigns