DEV Community

myougaTheAxo
myougaTheAxo

Posted on

Firebase In-App Messaging: Custom Banners and Smart Targeting

Firebase In-App Messaging (IAM) displays targeted messages without push notifications. Learn custom banners, targeting rules, and SnackbarHost integration.

Setup and Dependencies

implementation("com.google.firebase:firebase-inappmessaging-display-ktx")
Enter fullscreen mode Exit fullscreen mode

Implement Custom Display

import com.google.firebase.inappmessaging.ktx.inAppMessaging
import com.google.firebase.ktx.Firebase

val iapMessaging = Firebase.inAppMessaging

// Programmatic message triggering
iapMessaging.triggerEvent("user_sign_up")
Enter fullscreen mode Exit fullscreen mode

Create Custom Banner Composable

@Composable
fun CustomIAMBanner(
    title: String,
    message: String,
    actionLabel: String,
    onAction: () -> Unit
) {
    Surface(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp),
        color = MaterialTheme.colorScheme.primary,
        shape = RoundedCornerShape(8.dp)
    ) {
        Column(modifier = Modifier.padding(16.dp)) {
            Text(title, fontSize = 18.sp, fontWeight = FontWeight.Bold)
            Text(message, fontSize = 14.sp, modifier = Modifier.padding(top = 8.dp))
            Button(
                onClick = onAction,
                modifier = Modifier
                    .align(Alignment.End)
                    .padding(top = 12.dp)
            ) {
                Text(actionLabel)
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Integrate with SnackbarHost

@Composable
fun AppScaffold() {
    val snackbarHostState = remember { SnackbarHostState() }

    Scaffold(
        snackbarHost = { SnackbarHost(snackbarHostState) }
    ) { padding ->
        // Content
    }
}
Enter fullscreen mode Exit fullscreen mode

Remote Configuration

Configure targeting via Firebase Console:

  • Audience: User properties, custom events
  • Schedule: Immediate or recurring
  • Design: Text, image, action buttons

IAM messages are event-driven and require no user interaction to be displayed. Perfect for feature announcements and promotional campaigns.


8 Android app templates (Habit Tracker, Budget Manager, Task Manager, and more) available on Gumroad

Top comments (0)