그로스 액션 (Growth Action) 연동하기 [Flutter]
팔로우시작하기
디파이너리 그로스액션은 고객사의 인게이지먼트 마케팅 활동을 돕기 위한 기능을 제공합니다.
[그로스액션 (Growth Action) 서비스 알아보기]
디파이너리가 제공하는 기능을 이용하여 오디언스 그룹을 생성하고 각 오디언스를 타겟으로 하는 개인화된 마케팅을 진행할 수 있습니다.
[[인용:안내:보통]] 그로스액션을 이용하기 위해서는 디파이너리 유료플랜 이용이 필요합니다. [이용 문의하기]
필수 사항
디파이너리 그로스 액션 기능을 연동하기 위해서는 디파이너리(애드브릭스) SDK 연동이 필요합니다.
adbrix 기본 연동 단계까지 완료해야 그로스액션 연동이 가능합니다.
Android 푸시 서비스 설정
Flutter 에서 Growth Action 을 사용하기 위해서는 Flutter 프로젝트 내 Android / iOS 프로젝트 내에 푸시 메시지 수신을 위한 세팅이 필요합니다.
Firebase 연동
디파이너리 그로스 액션 기능을 연동하기 Firebase Cloud Messaging SDK (이하 FCM) 연동이 필요합니다.
아래 첨부된 가이드에 따라 Firbase 등록 후 FCM SDK 를 설치합니다.
Firebase Server Key, Sender ID 등록
디파이너리 그로스 액션 이용을 위해서는 디파이너리 콘솔에 Firebase Server Key / Sender ID 를 등록해야 합니다.
Firebase Server Key / Server ID 는 Firebase 콘솔 -> 설정 -> 클라우드 메시징 에서 확인하실 수 있습니다.
a. Firebase 콘솔에서 Firebase Server Key, Sender ID 를 확인합니다. [Firebase Severkey / Sender ID 확인 방법]
b. adbrix 콘솔의 Growth Action - Settings 메뉴에 확인한 키값을 입력합니다.
푸시 수신 설정
AndroidManifest.xml 에 아래 리시버를 등록합니다.
<receiver android:name="com.igaworks.v2.core.push.notification.AbxPushReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.igaworks.v2.core.pushServiceImplement.CLIENT_PUSH_RECEIVE"/> </intent-filter> </receiver>
작성하신 FirebaseMessagingService의 onMessageReceived내에 AdbrixrmFlutterPlugin.onMessageReceived를 사용하여 푸시 수신 설정을 합니다.
public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); AdbrixrmFlutterPlugin.onMessageReceived(getApplicationContext(), remoteMessage); } }
Token 값 설정
adbrix에 Firebase 의 Token 값을 설정하기 위해서는 FirebaseMessagingService의 onNewToken()내에 AdbrixrmFlutterPlugin.setRegistrationId를 사용하여 Token 값을 추가합니다.
public class MyFirebaseMessagingService extends FirebaseMessagingService{
@Override
public void onNewToken(String token){
Log.d(TAG, "Refreshed token: " + token);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
// Send token data to AdBrix
AdbrixrmFlutterPlugin.setRegistrationId(token);
}
}
그리고 사용하는 Application 클래스에 다음과 같이 Token 값이 갱신 될 수 있도록 다음 코드를 추가합니다.
public class MyApplicationClass extends FlutterApplication { @Override public void onCreate() { super.onCreate(); refreshToken(); } private void refreshToken(){ FirebaseMessaging.getInstance().getToken() .addOnCompleteListener(new OnCompleteListener<String>() { @Override public void onComplete(@NonNull Task<String> task) { if (!task.isSuccessful()) { return; } String token = task.getResult(); AdbrixrmFlutterPlugin.setRegistrationId(token); } }); } }
푸시 아이콘 및 색상 설정
푸시 수신시 노출되는 아이콘 및 앱 이름의 색상을 설정합니다.
AdbrixrmFlutterPlugin.setPushIconStyle("smallicon","largeicon",0x1000FF00);
이렇게 설정된 푸시 아이콘은 아래와 같이 노출 됩니다.
[[인용:위험:보통]]주의사항
1) 이미지 파일 이름은 확장자를 뺀 이름만 입력합니다.
2) 모든 해상도의 Flutter 프로젝트 내 android 프로젝트 내에 있는 Drawable 폴더에 해당 이름의 이미지를 모두 추가해야 합니다.
3) 서버 푸시에서 largeIcon 을 설정하였다면 해당 아이콘이 우선적으로 노출됩니다.
푸시 채널 설정
Android 8.0 이상에서 알림을 만들기 위해서는 NotificationChannel을 이용해야합니다. 해당 API를 사용하기 위해 반드시 AdbrixrmFlutterPlugin.setPushEnable(true);가 먼저 적용되어야 합니다.
알림 채널의 이름, 설명, 푸시 우선 순위, 진동 여부를 설정합니다. (1개의 채널만 생성 합니다)
AdbrixrmFlutterPlugin.setNotificationChannel(this,"myPushChannelName", "my Channel description", NotificationManager.IMPORTANCE_HIGH, true);
채널 중요도(importance)는 아래를 리스트를 참고 부탁드립니다. 채널 중요도(importance)를 default와 high로 설정하실 경우에만, vibration 기능을 사용하실 수 있습니다.
- 4 : NotificationManager.IMPORTANCE_HIGH : 알림 표시 ON / 소리 / 팝업으로 표시
- 3 :NotificationManager.IMPORTANCE_DEFAULT : 알림 표시 ON / 소리
- 2 : NotificationManager.IMPORTANCE_LOW : 알림 표시 ON / 무음 / 알림 최소화 OFF
- 1 : NotificationManager.IMPORTANCE_MIN : 알림 표시 ON / 무음 / 알림 최소화 ON
- 0 : NotificationManager.IMPORTANCE_NONE : 알림 표시 OFF
[[인용:위험:보통]]주의사항
channelName과 channelDescription은 해당 API를 이용해 언제나 변경 가능합니다. 하지만, channel이 생성된 후 importance와 vibration 여부는 변경할 수 없으니 참고를 부탁드립니다.
푸시 알림 설정
푸시 알림의 노출 정도를 설정합니다. 아래의 푸시 알림 설정 API는 Android 8.0 미만에서만 사용이 가능합니다.
//App.js
// 1 : PRIORITY_HIGH : 헤드업 알림 사용
let priority = 1;
// 1 : VISIBILITY_PUBLIC : 전체 내용을 잠금화면에 표시
let visibility = 1;
AdBrixRm.setNotificationOption(priority, visibility);
헤드업 알림 설정 (PRIORITY)
- 2 : PRIORITY_MAX : 헤드업 알림 사용
- 1 : PRIORITY_HIGH : 헤드업 알림 사용
- 0 : PRIORITY_DEFAULT : 헤드업 알림을 사용하지 않음
- -1 :PRIORITY_LOW : 헤드업 알림을 사용하지 않음
- -2 : PRIORITY_MIN : 헤드업 알림을 사용하지 않음
잠금화면 알림 설정 (VISIBILITY)
- -1 : VISIBILITY_SECRET : 잠금화면 알림을 사용하지 않음
- 0 : VISIBILITY_PRIVATE : 잠금화면 알림은 표시되나, 내용은 표시되지 않음
- 1 : VISIBILITY_PUBLIC : 전체 내용을 잠금화면에 표시
iOS 푸시 서비스 설정
APNS 인증서 등록
iOS 그로스 액션 서비스를 이용하기 위해 인증서를 등록합니다.
디파이너리 콘솔 / Growth Action / Settings / iOS Push Setting 에서 등록합니다. [인증서는 어떻게 등록하나요?]
[[인용:경고:보통]] 꼭 확인하세요.
- 암호가 없는 p12 인증서를 등록해야 합니다.
- p12 인증서는 Production 타입으로 등록해야 합니다.
- iOS 그로스 액션 서버 푸시는 Production 환경에서만 동작합니다.
Capability 추가
iOS 그로스액션 서비스 연동을 위해 아래 사항을 완료합니다.
- 앱의 Signing & Capabilities -> Capability 에 Background Modes, Push Notifications 를 추가
- Background Modes 에는 Remote notifications 를 체크
프레임워크 추가
iOS 그로스액션 서비스 사용을 위해 아래 사항을 완료합니다.
- General 항목에서 NotificationCenter.framework, UserNotifications.framework 를 추가합니다.
Notification Service Extension 추가
iOS 의 그로스액션 사용을 위해 Notification Service Extension 을 추가합니다.
a. Xcode 하단의 '+' 버튼 클릭
b. Notification Service Extension 을 선택하고 Next 버튼 클릭
c. Product Name 을 입력하고 완료
d. 해당 Extension 의 General 설정에 AdBrixRmKit.xcframework 를 추가합니다.
프레임워크는 현재 프로젝트의 Pods -> AdBrixRmKit 폴더에 있습니다.
e. Extension 설정이 완료되면 해당 폴더에 자동으로 추가된 NotificationService 파일을 열고 아래와 같이 수정합니다.
//NotificationService.swift import UserNotifications import AdBrixRmKit class NotificationService : AdBrixPushService {}
//NotificationService.h #import <UserNotifications/UserNotifications.h> #import <AdBrixRmKit/AdBrixPushServiceObjC.h> @interface NotificationService : AdBrixPushServiceObjC @end //NotificationService.m #import "NotificationService.h" @interface NotificationService () @end
AppDelegate 수정
iOS 그로스액션 서비스 이용을 위해 AppDelegate 를 아래 내용을 추가, 수정합니다.
a. Device Token 값 가져오기
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){ AdbrixrmFlutterPlugin.setRegistrationId(deviceToken: deviceToken) }
/- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [AdbrixrmFlutterPlugin setRegistrationIdWithDeviceToken:deviceToken]; }
b. didFinishLaunchingWithOptions 에 사용자 알림 사용 권한 동의에 따라 푸시 On / Off 기능 추가
class AppDelegate: FlutterAppDelegate, UNUserNotificationCenterDelegate { ... let unCenter = UNUserNotificationCenter.current() unCenter.delegate = self let options : UNAuthorizationOptions = [.alert,.sound,.badge] unCenter.requestAuthorization(options: options, completionHandler: {(granted,error) in if granted{ DispatchQueue.main.async { // If Push permission is granted enable AdBrix Push AdbrixrmFlutterPlugin.setPushEnable(toPushEnable: true) application.registerForRemoteNotifications() UIApplication.shared.registerForRemoteNotifications() } } else{ // If Push permission is not granted disable AdBrix Push AdbrixrmFlutterPlugin.setPushEnable(toPushEnable: false) } }) ... }
//AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if(granted){ [[UIApplication sharedApplication] registerForRemoteNotifications]; [AdbrixrmFlutterPlugin setPushEnableToPushEnable:true]; } else{ [AdbrixrmFlutterPlugin setPushEnableToPushEnable:false]; } }]; ... }
[[인용:경고:보통]]기본 설정값 확인
디파이너리 기본 설정값은 'Push off' 입니다.
따라서 그로스 액션 연동 완료 후 사용자들에게 푸시 수신 동의를 받은 후 Push On API 를 호출해야 합니다.
기존에 푸시 수신 동의를 받은 사용자들 역시 푸시 수신을 위해서 Push On API 를 호출해야 합니다.
c. 푸시 클릭 트랙킹 함수 추가
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { //remote push 트래킹 AdbrixrmFlutterPlugin.remotePushOpen(center: center, response: response)
//local push 트래킹
AdbrixrmFlutterPlugin.localPushOpen(center: center, response: response) completionHandler() }
- (void) userNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)(void))completionHandler{
//remote push 트래킹 [AdbrixrmFlutterPlugin remotePushOpenWithCenter:center response:response];
//local push 트래킹
[AdbrixrmFlutterPlugin localPushOpenWithCenter:center response:response]; completionHandler(); }
Push 사용하기
Push On / Off
adbrix 그로스액션 서비스를 이용하기 위해서는 반드시 연동해야하는 필수 API 입니다. 이 API 로 푸시 서비스를 관리할 수 있습니다.
AdbrixrmFlutterPlugin.setPushEnable(true) // Push On AdbrixrmFlutterPlugin.setPushEnable(false) // Push Off
[[인용:경고:보통]]기본 설정값 확인
디파이너리의 기본 설정값은 'Push off' 입니다.
따라서 그로스 액션 연동 완료 후 사용자들에게 푸시 수신 동의를 받은 후 Push On API 를 호출해야 합니다.
기존에 푸시 수신 동의를 받은 사용자들 역시 푸시 수신을 위해서 Push On API 를 호출해야 합니다.
Set Kakao ID
카카오 채널을 이용하실 경우, 카카오 SDK를 통해 가져오신 ID를 디파이너리 서버에 등록해야 합니다.
//dart
AdbrixRm.setKakaoId("kakaoID");
푸시 알림 리스너
푸시 서비스에 대한 리스너를 설정합니다. 이를 통해 딥링크가 포함된 푸시의 딥링크 정보를 전달받을 수 있습니다. 푸시 리스너는 Android / iOS 프로젝트에서 설정을 추가 후 Flutter에 리스너를 추가합니다.
Android
Application 클래스 내 리스너를 추가합니다.
public class MyApplicationClass extends FlutterApplication { @Override public void onCreate() { super.onCreate();
//remote push 트래킹 AdbrixrmFlutterPlugin.setRemotePushMessageListener(); //local push 트래킹 AdbrixrmFlutterPlugin.setLocalPushMessageListener(); }
}
Flutter
Andoid / iOS 설정이 완료되면 아래와 같이 Flutter 프로젝트 내 푸시 리스너를 추가합니다.
import 'package:adbrixrm_flutter/adbrixrm.dart';
...
...
AdBrixRm.setPushLocalCallbackListener((event) {
debugPrint("PUSH_LOCAL = $event");
});
AdBrixRm.setPushRemoteCallbackListener((event) {
debugPrint("PUSH_REMOTE = $event");
});
In-App Message
디파이너리 인앱 메시지는 별도의 연동이 필요하지 않습니다.
디파이너리 SDK를 통해서 전달된 이벤트를 트리거로 하여 인앱 메시지를 노출할 수 있고, 디파이너리 콘솔에서 모든 설정을 진행할 수 있습니다.
클릭 이벤트 리스너
유저의 인앱 메시지 클릭 이벤트를 설정한 리스너를 통해 전달합니다.
이 리스너를 이용하여 클릭 이벤트에 대한 추가 액션을 정의할 수 있습니다.
Android
Application 클래스 내 리스너를 추가합니다.
public class MyApplicationClass extends FlutterApplication { @Override public void onCreate() { super.onCreate(); AdbrixrmFlutterPlugin.setInAppMessageClickListener();
} }
iOS
AppDelegate 클래스 내 didFinishLaunchingWithOptions 에 아래와 같이 추가합니다.
@objc class AppDelegate: FlutterAppDelegate{
AdbrixrmFlutterPlugin.setInAppMessageClickListener() }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
[AdbrixrmFlutterPlugin setInAppMessageClickListener];
return [super application:application didFinishLaunchingWithOptions:launchOptions]; }
Flutter
Andoid / iOS 설정이 완료되면 아래와 같이 Flutter 프로젝트 내 in-app message 리스너를 추가합니다.
AdBrixRm.setOnReceiveInAppMessageClickListener((event) {
debugPrint("IAM_CLICK = $event");
});
클릭 리스너 전달 값 상세
클릭 리스너를 통해 전달되는 값의 타입과 예시는 다음과 같습니다.
- actionId (String) : button_1, button_2, image, sticky
- actionType (String) : close, deeplink_and_close, weblink, weblink_and_close, dont_show_me_today_and_close
- actionArg (String) : weblink address, deeplink path
- isClosed (Boolean) : 인앱 메시지가 닫혔는지 여부.