그로스 액션 (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개의 채널만 생성 합니다)
Android(JAVA)
AdbrixrmFlutterPlugin.setNotificationChannel("myPushChannelName", "my Channel description");
Flutter(Dart)
AdBrixRm.setNotificationChannel("channelName", "channelDescription");
푸시 알림 설정
푸시 알림의 노출 정도를 설정합니다. 아래의 푸시 알림 설정 API는 Android 8.0 미만에서만 사용이 가능합니다.
AdbrixrmFlutterPlugin.setNotificationOption(Context context, int priority, int 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)
completionHandler() }
- (void) userNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)(void))completionHandler{
//remote push 트래킹 [AdbrixrmFlutterPlugin remotePushOpenWithCenter:center response:response];
completionHandler(); }
d. 앱 실행 중 푸시 메시지 노출 여부를 설정하기 위한 코드 추가
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { AdbrixrmFlutterPlugin.willPresentRemotePush(notification: notification, completionHandler: completionHandler) }
- (void) userNotificationCenter:(UNUserNotificationCenter )center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler {
[AdbrixrmFlutterPlugin willPresentRemotePush:notification completionHandler: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 를 호출해야 합니다.
푸시 알림 리스너
푸시 서비스에 대한 리스너를 설정합니다. 이를 통해 딥링크가 포함된 푸시클릭에 대한 핸들링과 푸시의 딥링크 정보를 전달받을 수 있습니다. 푸시 리스너는 Android / iOS 프로젝트에서 설정을 추가 후 Flutter에 리스너를 추가합니다.
Android
Application 클래스 내 리스너를 추가합니다.
public class MyApplicationClass extends FlutterApplication { @Override public void onCreate() { super.onCreate();
...
... AdbrixrmFlutterPlugin.setRemotePushMessageListener();
...
... }
}
iOS
Appdelegate 클래스 내 리스너를 추가합니다.
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
...
...
AdbrixrmFlutterPlugin.setRemotePushMessageListener() ...
... }
//AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ ...
...
[AdbrixrmFlutterPlugin setRemotePushMessageListener]; ...
... }
Flutter
Andoid / iOS 설정이 완료되면 아래와 같이 Flutter 프로젝트 내 푸시 리스너를 추가합니다.
import 'package:adbrixrm_flutter/adbrixrm.dart';
...
...
AdBrixRm.setPushRemoteCallbackListener((event) {
debugPrint("PUSH_REMOTE = $event");
});
알림 구독 및 거부 설정
디파이너리 그로스 액션 기능을 연동하기 위해서는 알림에 대한 구독 설정이 필요합니다. SDK에서는 푸시 뿐만 아닌 다른 채널에 대해서 구독 및 거부 설정이 가능하며 현재 설정되어 있는 값을 가져오는 기능도 같이 제공합니다.
[[인용:경고:보통]] 해당 기능은 유저오디언스 기반으로 동작합니다. 따라서 설정 전에 반드시 AdBrixRm.login() API를 호출하여 user_id를 설정해주세요.
알림 구독 및 거부하기
디파이너리 서버로 사용자의 알림 수신 동의 값을 설정합니다.
Flutter
Future<void> setSubscriptionStauts(
{required bool info,
required bool marketing,
required bool marketingPush,
required bool marketingSms,
required bool marketingKakao,
required bool marketingNight,
required bool marketingNightPush,
required bool marketingNightSms,
required bool marketingNightKakao}) async
//사용 예시 void setSubscriptionStatus() async {
try {
await AdBrixRm.setSubscriptionStauts(
info: true,
marketing: true,
marketingPush: true,
marketingSms: true,
marketingKakao: false,
marketingNight: false,
marketingNightPush: false,
marketingNightSms: false,
marketingNightKakao: false);
_alert("success");
} catch (e) {
_alert(e.toString());
}
}
- 파라미터 정보
- info : 정보성 알림
- marketing : 광고성 알림
- marketingPush : 광고성 알림 푸시 채널
- marketingSms : 광고성 알림 SMS 채널
- marketingKakao : 광고성 알림 알림톡 채널
- marketingNight : 야간 광고성 알림
- marketingNightPush : 야간 광고성 알림 푸시 채널
- marketingNightSms : 야간 광고성 알림 SMS 채널
- marketingNightKakao : 야간 광고성 알림 알림톡 채널
[[인용:경고:보통]] 정보성 알림 수신 동의 여부는 광고성 알림 수신 동의 여부의 상위개념으로 취급합니다. 따라서 정보성 플래그가 UNSUBSCRIBED라면 광고성 플래그가 SUBSCRIBED 여도 푸시가 발송되지 않습니다.
알림 구독 정보 가져오기
Flutter
Future<Map?> getSubscriptionStatus() async
//리턴 Map
["informative": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_push": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_sms": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_kakao": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_night": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_night_push": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_night_sms": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED",
"marketing_night_kakao": "SUBSCRIBED" || "UNSUBSCRIBED" || "UNDEFINED"]
// 사용 예시 void getSubscriptionStatus() async {
try {
var getResult = await AdBrixRm.getSubscriptionStatus();
var toShow = """
informative ${getResult!["informative"]}
marketing ${getResult["marketing"]}
m_push ${getResult["marketing_push"]}
m_sms ${getResult["marketing_sms"]}
m_kakao ${getResult["marketing_kakao"]}
m_night ${getResult["marketing_night"]}
m_night_push ${getResult["marketing_night_push"]}
m_night_sms ${getResult["marketing_night_sms"]}
m_night_kakao ${getResult["marketing_night_kakao"]}
""";
_alert(toShow);
} catch (e) {
_alert(e.toString());
}
}
카카오톡 설정
카카오 알림톡, 친구톡 사용을 위한 설정입니다. *KAKAOID: 카카오 싱크 API를 통해 받은 10자리 카카오 ID
Flutter
Future<void> setKakaoId({required String kakaoId}) async
//사용 예시 void _setKakao() async {
try {
await AdBrixRm.setKakaoId(kakaoId: "123412341234");
_alert("success");
} catch (e) {
var s = e as PlatformException;
_alert(s.code);
}
}
SMS 설정
SMS 사용을 위한 설정입니다. *PHONE_NUMBER :E.164를 준수하는 국가코드 + 번호에서 "+"를 제외한 값 (예시 : 8210********)
Flutter
Future<void> setPhoneNumber({required String phoneNumber}) async
//사용 예시 void _setPhoneNumber() async {
try {
await AdBrixRm.setPhoneNumber(phoneNumber: "821012345678");
_alert("success");
} catch (e) {
var s = e as PlatformException;
_alert(s.code);
}
}
Pop-up Message
디파이너리 팝업 메시지는 별도의 연동이 필요하지 않습니다.
디파이너리 SDK를 통해서 전달된 이벤트를 트리거로 하여 팝업 메시지를 노출할 수 있고, 디파이너리 콘솔에서 모든 설정을 진행할 수 있습니다.
팝업 메시지 딥링크
네이티브에 인앱메시지 클릭 이벤트 리스너가 등록되어 있다면, 팝업 메시지에 설정되어있는 딥링크를 사용할 경우 딥링크 리스너 코드가 호출이 됩니다.
import 'adbrixrm_flutter/adbrixrm.dart'
.
.
.
//다음 연동 위치는 예시입니다. 필요한 곳에 알맞게 연동해주세요.
@override
void initState() {
super.initState();
AdBrixRm.setDeeplinkListener((deeplinkString) {
debugPrint("DEEPLINK = $deeplinkString");
});
}
[[인용:안내:보통]] 네이티브 os의 딥링크 코드도 호출되니 설정에 유의해주세요
클릭 이벤트 리스너
유저의 팝업 메시지 클릭 이벤트를 설정한 리스너를 통해 전달합니다.
이 리스너를 이용하여 클릭 이벤트에 대한 추가 액션을 정의할 수 있습니다.
Android
Application 클래스 내 리스너를 추가합니다.
public class MyApplicationClass extends FlutterApplication { @Override public void onCreate() { super.onCreate(); AdbrixrmFlutterPlugin.setInAppMessageClickListener();
} }
iOS
AppDelegate 클래스 내 didFinishLaunchingWithOptions 에 아래와 같이 추가합니다.
@objc class AppDelegate: FlutterAppDelegate{
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
...
... AdbrixrmFlutterPlugin.setInAppMessageClickListener()
...
... } }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
...
[AdbrixrmFlutterPlugin setInAppMessageClickListener];
...
... }
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) : 팝업 메시지가 닫혔는지 여부.