앱 삭제 추적
앱 제거를 추적하여 사용자 리텐션을 측정하고 리인게이지먼트 캠페인을 최적화하기 위해 Apple 푸시 알림 서비스(APN)를 Singular SDK와 연동할 수 있습니다.
중요: 앱 제거 추적을 사용하려면 앱에서 APN을 구성해야 합니다. 전체 구현에 대한 자세한 내용은 Apple의 사용자 알림 프레임워크 설명서를참조하세요.
전제 조건
Singular 플랫폼 구성
앱에서 앱 제거 추적을 구현하기 전에 iOS 앱 제거 추적 설정 가이드에 따라 Singular 플랫폼에서 앱을 구성합니다.
시스템 요구 사항
앱 제거 추적을 사용하려면 Apple 푸시 알림 서비스 및 특정 디바이스 구성이 필요합니다.
APN 요구 사항(출처):
- iOS 버전: 디바이스는 UserNotifications 프레임워크용 iOS 10.0 이상을 실행해야 합니다.
- APNs 인증서: Apple 개발자 포털에서 APNs 인증서 또는 토큰을 구성합니다.
- 푸시 기능: Xcode 프로젝트 설정에서 푸시 알림 기능을 활성화합니다.
- 사용자 권한: 푸시 알림에 대한 사용자 권한 요청 및 획득: 푸시 알림에 대한 사용자 권한 요청 및 획득
참고: 푸시 알림 권한을 거부하거나 APN을 지원하지 않는 기기를 사용하는 사용자는 제거를 추적하지 않습니다.
구현 단계
1단계: 푸시 알림 활성화
푸시 알림을 아직 활성화하지 않은 경우 푸시 알림을 지원하도록 Xcode 프로젝트를 구성합니다.
- Xcode에서 프로젝트 열기
- 앱 대상을 선택하고 서명 및 기능으로이동합니다.
- 기능 + 푸시 알림을클릭하고 푸시 알림을추가합니다.
- 백그라운드 모드에서 원격 알림이 선택되어 있는지 확인합니다.
2단계: 사용자 승인 요청
UserNotifications 프레임워크를 사용하여 사용자에게 푸시 알림을 받을 수 있는 권한을 요청합니다.
import UIKit
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set notification delegate
UNUserNotificationCenter.current().delegate = self
// Request authorization for notifications
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
if let error = error {
print("Notification authorization error: \(error.localizedDescription)")
}
if granted {
// Register for remote notifications on main thread
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
}
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set notification delegate
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// Request authorization for notifications
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
UNAuthorizationOptionBadge |
UNAuthorizationOptionSound;
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (error) {
NSLog(@"Notification authorization error: %@", error.localizedDescription);
}
if (granted) {
// Register for remote notifications on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
}
}];
return YES;
}
@end
3단계: APNs 디바이스 토큰 등록
APNs 디바이스 토큰을 검색하여 제거 추적을 위해 Singular로 전송합니다.
토큰 검색 및 설정
didRegisterForRemoteNotificationsWithDeviceToken 콜백을 구현하여 APNs 토큰을 캡처하고 이를 Singular에 등록합니다.
import Singular
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Register the device token with Singular for uninstall tracking
Singular.registerDeviceToken(forUninstall: deviceToken)
print("APNs device token registered with Singular")
// Also send to your server if needed for your own push notifications
sendTokenToServer(deviceToken)
}
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register for remote notifications: \(error.localizedDescription)")
}
private func sendTokenToServer(_ deviceToken: Data) {
// Implement your server communication logic here
}
#import <Singular/Singular.h>
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Register the device token with Singular for uninstall tracking
[Singular registerDeviceTokenForUninstall:deviceToken];
NSLog(@"APNs device token registered with Singular");
// Also send to your server if needed for your own push notifications
[self sendTokenToServer:deviceToken];
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Failed to register for remote notifications: %@", error.localizedDescription);
}
- (void)sendTokenToServer:(NSData *)deviceToken {
// Implement your server communication logic here
}
모범 사례: 토큰을 받으면 즉시 registerDeviceTokenForUninstall 으로 호출하여 첫 번째 앱 세션부터 앱 제거 추적이 활성화되도록 합니다.
토큰 데이터 형식
Apple에서 받은 기본 바이너리 형식의 APNs 디바이스 토큰을 Singular에 전달합니다.
중요: APNs 토큰은 바이너리 데이터(NSData/Data)입니다. 변환하지 않고 바로 Singular에 전달하세요. 앱에서 다른 용도로 토큰을 16진수 문자열로 변환해야 하는 경우 Singular에 대한 원본 NSData 개체를 유지하세요.
예제 16진수 형식:b0adf7c9730763f88e1a048e28c68a9f806ed032fb522debff5bfba010a9b052
대체 구성 방법
초기화 중 토큰 설정
SDK를 초기화하기 전에 APN 토큰을 사용할 수 있는 경우 SingularConfig 객체에서 토큰을 구성합니다.
// Get cached token if available
if let cachedToken = getCachedAPNsToken() {
let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET")
config?.apnsDeviceToken = cachedToken
Singular.start(config)
}
func getCachedAPNsToken() -> Data? {
// Implement your token caching logic here
return nil
}
// Get cached token if available
NSData *cachedToken = [self getCachedAPNsToken];
if (cachedToken) {
SingularConfig *config = [[SingularConfig alloc]
initWithApiKey:@"SDK_KEY"
andSecret:@"SDK_SECRET"];
config.apnsDeviceToken = cachedToken;
[Singular start:config];
}
- (NSData *)getCachedAPNsToken {
// Implement your token caching logic here
return nil;
}
메소드 서명:
@property (nonatomic, strong) NSData *apnsDeviceToken;
검증 및 문제 해결
구현 확인
제거 추적이 올바르게 작동하는지 확인합니다.
- 로그를 확인합니다: 로그에 APN 토큰 등록이 나타나는지 확인합니다.
- 토큰 생성 테스트: 앱을 처음 실행할 때 토큰이 생성되는지 확인합니다.
- 대시보드 모니터링: 24-48시간 후 Singular 대시보드에서 제거 추적 데이터를 확인합니다.
- 권한 테스트: 알림 권한 부여 프롬프트가 올바르게 표시되고 작동하는지 확인합니다.
일반적인 문제
- 토큰이 생성되지 않음: Xcode에서 푸시 알림 기능이 활성화되어 있고 Apple 개발자 포털에서 APN 인증서가 구성되어 있는지 확인합니다.
- 사용자가 권한을 거부했습니다: 거부된 알림 권한을 정상적으로 처리하는 로직을 구현합니다.
- 누락된 데이터: 디바이스가 iOS 10.0 이상을 실행하고 사용자에게 알림 권한이 부여되었는지 확인합니다.
- 구성 오류: Singular 플랫폼 설정에서 제거 추적이 활성화되어 있는지 확인합니다.
- 시뮬레이터 제한: iOS 시뮬레이터에서는 APN 토큰을 사용할 수 없으므로 실제 디바이스에서 테스트하세요.
추가 리소스: 자세한 문제 해결 방법은 제거 추적 설정 가이드및 Apple의 사용자 알림 설명서를 참조하세요.