iOS SDK - 푸시 알림 지원

푸시 알림 지원

Apple Push Notification Service(APNs)를 Singular SDK와 연동하여 푸시 알림과의 사용자 상호작용을 추적함으로써 리인게이지먼트 캠페인을 측정하고 전환을 정확하게 어트리뷰션하세요.

아래 구현 가이드라인을 따라 알림 데이터가 Singular SDK로 올바르게 전달되어 정확한 어트리뷰션이 이루어지도록 하세요.

푸시 알림을 추적해야 하는 이유: 푸시 알림은 리인게이지먼트를 유도하지만, 추적을 위해서는 올바른 연동이 필요합니다. Singular는 알림과 상호작용한 사용자가 적절하게 어트리뷰션되도록 보장하여 마케팅 캠페인과 참여 전략을 최적화합니다.

사전 요구 사항: APNs 토큰이 생성되고 Singular가 푸시 페이로드를 추출하려면 먼저 다음 사항이 모두 갖춰져 있는지 확인하세요:

  • 앱 타겟의 Xcode Signing & Capabilities 에서 Push Notifications 기능이 활성화되어 있어야 합니다.
  • APNs 키(.p8) 또는 인증서(.p12)가 해당 앱에 대해 Singular 대시보드에 업로드되어 있어야 합니다.
  • 앱은 aps-environment 엔타이틀먼트를 포함하는 프로비저닝 프로파일로 빌드되어야 합니다.
  • 테스트는 실제 디바이스에서 수행해야 합니다 — APNs 토큰은 iOS 시뮬레이터에서는 발급되지 않습니다.
  • Singular.start(_:) 가 실행되어야만 SDK가 pushNotificationLinkPath 를 통해 알림 페이로드에서 Singular 링크를 추출할 수 있습니다.

구현 가이드

푸시 알림 등록

사용자에게 푸시 알림 수신 권한을 요청하고 UNUserNotificationCenter를 사용하여 앱을 APNs에 등록하세요.

Swift Objective-C
import UserNotifications

// Set the current instance as the delegate for UNUserNotificationCenter
UNUserNotificationCenter.current().delegate = self

// Define the notification authorization options (alert, badge, sound)
let pushAuthOptions: UNAuthorizationOptions = [.alert, .badge, .sound]

// Request notification authorization from the user
UNUserNotificationCenter.current().requestAuthorization(options: pushAuthOptions) { granted, error in
    // If an error occurs during authorization, print the error description
    if let error = error {
        print("registerForPushNotifications : failure - \(error.localizedDescription)")
    }

    // If the user granted permission, register for remote notifications
    if granted {
        // Ensure registration is done on the main thread
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
        }
    }
}

모범 사례: 알림 권한 요청은 앱 라이프사이클 초기에, 이상적으로는 사용자에게 가치를 입증한 후에 수행하여 옵트인율을 높이세요.


알림 응답 처리

사용자가 푸시 알림을 탭할 때 알림 응답을 처리하고 페이로드 데이터를 Singular에 전달하여 추적하세요.

Swift Objective-C
func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {

    // Extract the notification payload
    let userInfo = response.notification.request.content.userInfo

    // Pass the notification data to Singular for tracking
    Singular.handlePushNotification(userInfo)

    // Call the completion handler to indicate processing is complete
    completionHandler()
}

모범 사례: 알림 처리가 완료되었음을 시스템에 알리기 위해 항상 완료 핸들러를 즉시 호출하세요. 완료가 지연되면 시스템 중요나 스로틀링이 발생할 수 있습니다.


푸시 페이로드를 위한 SDK 구성

SDK 구성에 푸시 알림 페이로드 셀렉터를 추가하여 Singular 링크가 알림 데이터 구조의 어느 위치에 있는지 지정하세요.

Swift Objective-C
func getConfig() -> SingularConfig? {
    guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
        return nil
    }

    // Configure push notification link paths
    config.pushNotificationLinkPath = [
        ["sng_link"],
        ["rootObj", "nestedObj", "anotherNested", "singularLink"]
    ]

    return config
}

// Start the Singular SDK with the configuration
if let config = getConfig() {
    Singular.start(config)
}

셀렉터 구성:

  • 단순 키: 페이로드의 최상위 키에는 ["sng_link"] 를 사용하세요
  • 중첩 키: 중첩된 JSON 구조를 탐색하려면 ["rootObj", "nestedObj", "key"] 를 사용하세요
  • 다중 경로: Singular 링크가 위치할 수 있는 여러 위치를 확인하기 위해 여러 셀렉터 배열을 정의하세요

검증 가이드

Start Session에서 페이로드 확인

start session API 호출을 검사하여 푸시 알림 링크가 Singular에 올바르게 전달되는지 확인하세요.

사용자가 알림을 탭하면 Singular SDK는 start session 요청의 singular_link 파라미터에 푸시 알림 페이로드를 포함합니다.

Start Session 요청 예시:

https://skan.singular.net:443/api/v1/start?
dnt=-1
&update_time=0
&singular_link=https://sl.sng.link/Cclbu/2a7n?_dl=com.singular.app&_smtype=3
&i=com.singular.SwiftScene
&sdk=Singular/12.7.1
&p=iOS
&v=18.2.1

대체 검증 방법: Singular SDK 콘솔을 사용하여 푸시 알림 추적을 검증하세요. Deeplink URL 필드를 확인하여 추적 링크가 올바르게 캡처되었는지 확인하세요.


고급 구성

ESP 도메인 구성

Singular 링크를 ESP(Email Service Provider) 또는 기타 타사 도메인으로 래핑하는 경우 외부 도메인을 구성하세요.

Swift Objective-C
func getConfig() -> SingularConfig? {
    guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
        return nil
    }

    // Configure ESP domains for wrapped links
    config.espDomains = ["sl.esp.link", "custom.domain.com"]

    return config
}

보안 참고 사항: 기본적으로 Singular의 Manage Links 페이지에 사전 정의된 sng.link 도메인만 허용됩니다. 래핑된 링크를 사용하는 경우 ESP 도메인을 명시적으로 구성하세요.


동적 딥링크 라우팅

동적 리디렉션 오버라이드를 사용하여 하나의 Singular 추적 링크를 구성함으로써 Singular 알림에서 여러 딥링크 목적지를 구현하세요.

사용 사례 예시: 여러 액션 옵션이 있는 속보 알림

  • 최신 뉴스 읽기: newsapp://article?id=12345
  • 인기 토픽: newsapp://trending
  • 스포츠: newsapp://sports

여러 추적 링크를 생성하는 대신 하나의 Singular 링크를 사용하고 사용자 선택에 따라 리디렉션을 동적으로 오버라이드하세요. 구현 세부 정보는 Singular 추적 링크에서 리디렉션 오버라이드 를 참조하세요.


중요 고려 사항

구현 참고 사항

  • 콜백 핸들러 없음: singularLinksHandler 와 달리, 푸시 알림 기능은 페이로드 콜백을 제공하지 않습니다. 사용자를 앱 내 특정 콘텐츠로 라우팅하려면 자체 딥링크 로직을 구현하세요
  • 어트리뷰션 흐름: 사용자가 알림을 탭하면 Singular는 페이로드를 검색하여 Singular.start() 에 의해 트리거되는 start session 이벤트에 포함시킵니다. 백엔드는 이 데이터를 처리하여 푸시 알림 터치포인트를 어트리뷰션하고 리인게이지먼트 추적을 등록합니다
  • 도메인 제한: 기본적으로 Manage Links 페이지의 Singular 링크 도메인( sng.link )만 허용됩니다. 래핑된 링크의 경우 espDomains 를 사용하여 ESP 도메인을 명시적으로 구성하세요

성공: 이러한 단계를 따르면 앱이 이제 Singular를 통해 푸시 알림 상호작용을 추적하여 캠페인 성과 인사이트를 개선하고 정확한 리인게이지먼트 어트리뷰션을 보장합니다.