> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# In-app popup event listener

> Listen for and handle in-app popup events with the Notifly SDK.

The Notifly SDK provides an event listener for in-app popups. Use the listener to run additional actions in your app when a user interacts with a popup.

> [tab] Android
>
> > [!NOTE]
> >
> > This feature requires Notifly Android SDK 1.16.1 or later.
>
> ```kotlin theme={null}
>   package com.your.project
>
>   import android.app.Application
>   import android.util.Log
>   import androidx.core.app.NotificationCompat
>   import androidx.core.content.ContextCompat
>   import tech.notifly.Notifly
>   import tech.notifly.push.interfaces.IInAppMessageEventListener
>
>   class SampleApplication : Application() {
>       override fun onCreate() {
>           super.onCreate()
>
>           // Initialize Notifly SDK
>           Notifly.initialize(
>               context = applicationContext,
>               projectId = BuildConfig.NOTIFLY_PROJECT_ID,
>               username = BuildConfig.NOTIFLY_USERNAME,
>               // password is a placeholder for backward compatibility. Do not use a real password or API Secret Key.
>               password = BuildConfig.NOTIFLY_USERNAME,
>           )
>
>           // Add Notifly in-app message event listener
>           Notifly.addInAppMessageEventListener(
>               object : IInAppMessageEventListener {
>                   override fun handleEvent(
>                       eventName: String,
>                       eventParams: Map<String, Any?>?,
>                   ) {
>                       Log.d("SampleApplication", "InAppMessage event dispatched: $eventName, $eventParams")
>                   }
>               },
>           )
>       }
>   }
> ```

> [tab] iOS
>
> > [!NOTE]
> >
> > This feature requires Notifly iOS SDK 1.16.1 or later.
>
> ```swift theme={null}
> import Firebase
> import notifly_sdk
> import UIKit
> import UserNotifications
>
> @main
> class AppDelegate: UIResponder, UIApplicationDelegate {
>     func application(
>         _: UIApplication,
>         didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
>     ) -> Bool {
>         ...
>         Notifly.initialize(
>             projectId: TestConstant.projectId, username: TestConstant.username,
>             // password is a placeholder for backward compatibility. Do not use a real password or API Secret Key.
>             password: TestConstant.username)
>
>         Notifly.addInAppMessageEventListener { eventName, eventParams in
>             print("In App Message Event: \(eventName)")
>             if let params = eventParams {
>                 print("In App Message Event Params: \(params)")
>             }
>         }
>         ...
>         return true
>     }
> }
> ```

> [tab] Flutter
>
> > [!NOTE]
> >
> > This feature requires Notifly Flutter SDK 2.1.0 or later. The event stream is available on Android and iOS. Web is not supported.
>
> ```dart theme={null}
> import 'package:flutter/material.dart';
> import 'package:notifly_flutter/notifly_flutter.dart';
> import 'dart:async';
>
> class MyApp extends StatefulWidget {
>  const MyApp({super.key});
>
>  @override
>  State<MyApp> createState() => _MyAppState();
> }
>
> class _MyAppState extends State<MyApp> {
>  StreamSubscription<InAppMessageEvent>? _subscription;
>
>  @override
>  void initState() {
>    super.initState();
>    _initNotifly();
>  }
>
>  Future<void> _initNotifly() async {
>    // Initialize Notifly SDK
>    await NotiflyPlugin.initialize(
>      projectId: 'YOUR_PROJECT_ID',
>      username: 'YOUR_USERNAME',
>      // `password` is a placeholder for backward compatibility. Do not use a real password or API Secret Key.
>      password: 'YOUR_USERNAME',
>    );
>
>    // Subscribe to in-app message events
>    _subscription = NotiflyPlugin.inAppEvents.listen(
>      (event) {
>        print('InAppMessage event dispatched: ${event.eventName}');
>        print('Event params: ${event.eventParams}');
>
>        // Handle specific events
>        switch (event.eventName) {
>          case 'main_button_click':
>            // Handle main button click
>            break;
>          case 'close_button_click':
>            // Handle close button click
>            break;
>        }
>      },
>      onError: (error, stackTrace) {
>        print('InAppMessage event error: $error');
>        print('Stack trace: $stackTrace');
>      },
>      cancelOnError: false, // Continue listening even after an error
>    );
>  }
>
>  @override
>  void dispose() {
>    _subscription?.cancel();
>    super.dispose();
>  }
>
>  @override
>  Widget build(BuildContext context) {
>    return MaterialApp(
>      home: Scaffold(
>        appBar: AppBar(title: const Text('Notifly Sample')),
>        body: const Center(child: Text('Notifly Initialized')),
>      ),
>    );
>  }
> }
> ```

> [tab] React Native
>
> > [!NOTE]
> >
> > This feature requires Notifly React Native SDK 4.6.0 or later and is available on Android and iOS.
>
> Initialize the SDK, then register an in-app popup event listener as shown below.
>
> ```typescript theme={null}
> import notifly from 'notifly-sdk';
>
> export async function initNotifly() {
>   await notifly.initialize({
>     projectId: 'YOUR_PROJECT_ID',
>     username: 'YOUR_USERNAME',
>     // `password` is a backward-compatibility placeholder. Do not enter a real password or API Secret Key.
>     password: 'YOUR_USERNAME',
>   });
>
>   const subscription = notifly.addInAppMessageEventListener((event) => {
>     console.log('InAppMessage event dispatched:', event.eventName);
>   });
>
>   return subscription;
> }
> ```
>
> In your app initialization code, keep the subscription returned by `await initNotifly()`. Call `subscription.remove()` when you no longer need to receive events. Register before triggering a popup; events that occurred before registration are not replayed.

## In-app popup event listener interface

> [tab] Android
>
> Implement the `handleEvent` method of `IInAppMessageEventListener` to listen for in-app popup events. The method receives the following parameters:
>
> **eventName** `String`
>
> The name of the event.
>
> **eventParams** `Map\<String, Any?\>?`
>
> Additional information about the event, or `null` if no parameters are provided.

> [tab] iOS
>
> Register an `InAppMessageEventListener` with `addInAppMessageEventListener`.
>
> **eventName** `String`
>
> The name of the event.
>
> **eventParams** `[String: Any]?`
>
> Additional information about the event, or `nil` if no parameters are provided.

> [tab] Flutter
>
> Subscribe to in-app popup events through the `NotiflyPlugin.inAppEvents` stream. Each event is an `InAppMessageEvent` object with the following properties:
>
> **eventName** `String`
>
> The name of the event.
>
> **eventParams** `Map\<String, dynamic\>?`
>
> Additional information about the event, or `null` if no parameters are provided.

> [tab] React Native
>
> Subscribe to in-app popup events with `notifly.addInAppMessageEventListener`. Each event is an `InAppMessageEvent` object with the following properties:
>
> **eventName** `string`
>
> The name of the event.
>
> **eventParams** `Record\<string, unknown\> | null`
>
> Additional information about the event. Values depend on the event and platform, and are `null` if no parameters are provided.

## In-app popup events

> [tab] Android
>
> The following `eventName` values are passed to `handleEvent`.
>
> * `in_app_message_show`: The in-app popup is displayed.
> * `main_button_click`: The user taps the main button in the popup.
> * `hide_in_app_message_button_click`: The user taps the **Do Not Show Again** button.
> * `close_button_click`: The user taps the close button in the popup.
> * `survey_submit_button_click`: The user taps the survey submit button.

> [tab] iOS
>
> The following `eventName` values are passed to `addInAppMessageEventListener`.
>
> * `in_app_message_show`: The in-app popup is displayed.
> * `main_button_click`: The user taps the main button in the popup.
> * `hide_in_app_message_button_click`: The user taps the **Do Not Show Again** button.
> * `close_button_click`: The user taps the close button in the popup.
> * `survey_submit_button_click`: The user taps the survey submit button.

> [tab] Flutter
>
> The following `eventName` values are passed through `NotiflyPlugin.inAppEvents`.
>
> * `in_app_message_show`: The in-app popup is displayed.
> * `main_button_click`: The user taps the main button in the popup.
> * `hide_in_app_message_button_click`: The user taps the **Do Not Show Again** button.
> * `close_button_click`: The user taps the close button in the popup.
> * `survey_submit_button_click`: The user taps the survey submit button.

> [tab] React Native
>
> The following `eventName` values are passed to `notifly.addInAppMessageEventListener`.
>
> * `in_app_message_show`: An in-app popup display event.
>
> * `main_button_click`: The user taps the main button in the popup.
>
> * `hide_in_app_message_button_click`: The user taps the **Do Not Show Again** button.
>
> * `close_button_click`: The user taps the close button in the popup.
>
> * `survey_submit_button_click`: The user taps the survey submit button.
>
> > [!NOTE]
> >
> > Android SDK 1.24.3, included in React Native SDK 4.6.0, has an existing issue: `survey_submit_button_click` is not delivered if the survey `extra_data` has no `link` field. iOS delivers the event under the same condition.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.