- Android
- iOS
- Flutter
- React Native
해당 기능은 노티플라이 Android SDK 1.16.1 이상 버전부터 지원됩니다.
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는 과거 호환용 placeholder입니다. 실제 비밀번호나 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")
}
},
)
}
}
해당 기능은 노티플라이 iOS SDK 1.16.1 이상 버전부터 지원됩니다.
import Firebase
import notifly_ios_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는 과거 호환용 placeholder입니다. 실제 비밀번호나 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
}
}
해당 기능은 노티플라이 Flutter SDK 2.1.0 이상 버전부터 지원됩니다.
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`는 과거 호환용 placeholder입니다. 실제 비밀번호나 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')),
),
);
}
}
해당 기능은 노티플라이 React Native SDK 4.6.0 이상 버전부터 Android와 iOS에서 지원됩니다.
import notifly from 'notifly-sdk';
export async function initNotifly() {
await notifly.initialize({
projectId: 'YOUR_PROJECT_ID',
username: 'YOUR_USERNAME',
// `password`는 과거 호환용 placeholder입니다. 실제 비밀번호나 API Secret Key를 넣지 마세요.
password: 'YOUR_USERNAME',
});
const subscription = notifly.addInAppMessageEventListener((event) => {
console.log('InAppMessage event dispatched:', event.eventName);
});
return subscription;
}
await initNotifly()로 반환받은 구독 객체를 보관하고, 더 이상 이벤트를 수신할 필요가 없을 때 subscription.remove()를 호출하세요. 팝업을 발생시키기 전에 등록해야 하며, 등록 전에 발생한 이벤트는 전달되지 않습니다.인앱 팝업 이벤트 리스너 인터페이스
- Android
- iOS
- Flutter
- React Native
IInAppMessageEventListener 인터페이스의 handleEvent 메서드를 구현하여 인앱 팝업에서 발생하는 이벤트들을 감지할 수 있습니다. 이 메서드는 다음과 같은 파라미터를 받습니다:addInAppMessageEventListener 메서드를 통해 InAppMessageEventListener를 등록할 수 있습니다.NotiflyPlugin.inAppEvents 스트림을 통해 인앱 팝업 이벤트를 구독할 수 있습니다. 각 이벤트는 InAppMessageEvent 객체로 전달되며, 다음과 같은 속성을 포함합니다:인앱 팝업 이벤트 목록
- Android
- iOS
- Flutter
- React Native
handleEvent로 전달되는 eventName 목록입니다.in_app_message_show: 인앱 팝업 노출.main_button_click: 팝업 내 메인 버튼 클릭.hide_in_app_message_button_click: 다시 보지 않기 버튼 클릭.close_button_click: 팝업 내 닫기 버튼 클릭.
addInAppMessageEventListener로 전달되는 eventName 목록입니다.in_app_message_show: 인앱 팝업 노출.main_button_click: 팝업 내 메인 버튼 클릭.hide_in_app_message_button_click: 다시 보지 않기 버튼 클릭.close_button_click: 팝업 내 닫기 버튼 클릭.survey_submit_button_click: 설문 조사 제출 버튼 클릭.
NotiflyPlugin.inAppEvents로 전달되는 eventName 목록입니다.in_app_message_show: 인앱 팝업 노출.main_button_click: 팝업 내 메인 버튼 클릭.hide_in_app_message_button_click: 다시 보지 않기 버튼 클릭.close_button_click: 팝업 내 닫기 버튼 클릭.survey_submit_button_click: 설문 조사 제출 버튼 클릭.
notifly.addInAppMessageEventListener로 전달되는 eventName 목록입니다.in_app_message_show: 인앱 팝업 표시 이벤트.main_button_click: 팝업 내 메인 버튼 클릭.hide_in_app_message_button_click: 다시 보지 않기 버튼 클릭.close_button_click: 팝업 내 닫기 버튼 클릭.survey_submit_button_click: 설문 조사 제출 버튼 클릭.
React Native SDK 4.6.0에 포함된 Android SDK 1.24.3에서는 설문
extra_data에 link 필드가 없으면 survey_submit_button_click 이벤트가 전달되지 않는 기존 문제가 있습니다. iOS에서는 해당 조건에서도 이벤트가 전달됩니다.