| 플랫폼 선택: | iOS+ Android Unity |
인앱 구매 (IAP)는 Apple App Store 또는 Google Play를 통해 모바일 앱에서 판매할 수 있는 디지털 콘텐츠 또는 기능으로, 앱에서 금융 거래를 처리할 필요가 없습니다. 인앱 구매의 예로는 구독 기반 콘텐츠 또는 특별 게임 피스가 있습니다.
Analytics의 인앱 구매 보고서에 IAP 이벤트가 표시됩니다.
Unity 앱의 경우 Analytics SDK가 iOS의 Apple App Store 및 Android의 Google Play와 통합됩니다.
대부분의 경우 Analytics SDK는 앱에서 API를 호출하지 않아도 IAP 이벤트를 자동으로 수집합니다. 설정 요구사항 및 추적 동작은 타겟 플랫폼에 따라 다릅니다.
- Android: Google Play 거래가 Google Play에 연결한 후 자동으로 추적됩니다. 코드를 변경할 필요가 없습니다.
- iOS (StoreKit 1): StoreKit 1 API를 사용하여 이루어진 App Store 거래가 자동으로 추적됩니다. 코드를 변경할 필요가 없습니다.
- iOS (StoreKit 2): StoreKit 2 API를 사용하여 이루어진 App Store 거래는 커스텀 Unity API를 사용하여 수동으로 로깅해야 합니다.
시작하기 전에
Google Analytics 시작하기의 설명에 따라 Firebase 프로젝트와 앱의 코드베이스를 설정합니다.
앱이 다음과 같은 플랫폼별 설정 요구사항을 충족하는지 확인합니다.
Android: Firebase 앱을 Google Play에 연결합니다.
iOS (StoreKit 1): 추가 설정이 필요하지 않습니다. StoreKit 1 추적이 자동으로 작동합니다.
iOS (StoreKit 2): 앱에서 Firebase Unity SDK v13.12.0 이상을 사용하고 있는지 확인합니다.
Google Play 결제, Apple StoreKit, Unity 인앱 구매의 플랫폼별 문서를 검토하여 인앱 구매 API를 숙지해야 합니다.
구현
Android
Android 앱의 경우 에 연결하는 즉시 IAP 이벤트를 측정할 수 있습니다.Google Play Unity 프로젝트에서 구매를 측정하기 위해 커스텀 코드를 작성할 필요가 없습니다.
iOS
iOS 앱의 경우 구현 전략은 앱에서 StoreKit 1을 사용하는지 StoreKit 2를 사용하는지에 따라 다릅니다.
StoreKit 1
구매 흐름에서 StoreKit 1을 사용하는 경우 애널리틱스 SDK가 IAP 이벤트를 자동으로 로깅합니다. 이러한 구매를 추적하기 위해 커스텀 코드를 추가할 필요가 없습니다.
StoreKit 2
구매 흐름에서 StoreKit 2를 사용하는 경우 거래 식별자 문자열을 LogAppleTransactionAsync()에 전달하여 확인된 거래를 수동으로 로깅해야 합니다.
using Firebase.Analytics; // Call this method once you have completed a StoreKit 2 transaction // and have the transaction identifier. public void LogPurchase(string transactionId) { FirebaseAnalytics.LogAppleTransactionAsync(transactionId).ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { Debug.LogError("Failed to log Apple purchase transaction: " + task.Exception); } else { Debug.Log("Successfully logged Apple purchase transaction"); } }); }
Unity IAP를 사용하여 거래 ID 가져오기
프로젝트에서 Unity의 표준 인앱 구매 패키지
(UnityEngine.Purchasing)를 사용하는 경우 거래 ID를 가져오는 방법은 사용 중인 Unity IAP API 버전에 따라 다릅니다.
Unity IAP v5.2 이상을 사용하는 확인 콜백
Unity IAP v5.2 이상에서는 확인 콜백의 Order 객체에서 Apple 관련 거래 정보에 직접 액세스할 수 있습니다. OriginalTransactionID 또는 현재 거래 ID를 LogAppleTransactionAsync()에 전달할 수 있습니다.
using UnityEngine.Purchasing; using Firebase.Analytics; using Firebase.Extensions; // Example using Unity IAP v5.2+ Order confirmation void OnPurchaseConfirmed(Order order) { #if UNITY_IOS if (order is ConfirmedOrder confirmedOrder) { var appleInfo = confirmedOrder.Info.Apple; if (appleInfo != null) { string transactionId = appleInfo.OriginalTransactionID; if (!string.IsNullOrEmpty(transactionId)) { // Log the StoreKit 2 transaction with Firebase Analytics FirebaseAnalytics.LogAppleTransactionAsync(transactionId).ContinueWithOnMainThread(task => { if (task.IsFaulted || task.IsCanceled) { Debug.LogError($"Failed to log Apple purchase transaction: {task.Exception}"); } else { Debug.Log("Successfully logged Apple purchase transaction"); } }); } else { Debug.LogWarning("Apple OriginalTransactionID is null or empty. Skipping Firebase logging."); } } } else if (order is FailedOrder failedOrder) { Debug.Log($"Purchase confirmation bypassed due to failure: {failedOrder.FailureReason}"); } #endif }
기존 ProcessPurchase 콜백
기존 ProcessPurchase 콜백을 사용하는 경우 구매한 제품에서 거래 식별자를 추출할 수 있습니다.
using UnityEngine.Purchasing; using Firebase.Analytics; using Firebase.Extensions; public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { // Extract the transaction ID from the purchased product string transactionId = args.purchasedProduct.transactionID; #if UNITY_IOS // Log the StoreKit 2 transaction with Firebase Analytics FirebaseAnalytics.LogAppleTransactionAsync(transactionId).ContinueWithOnMainThread(task => { if (task.IsFaulted || task.IsCanceled) { Debug.LogError($"Failed to log Apple purchase transaction: {task.Exception}"); } else { Debug.Log("Successfully logged Apple purchase transaction"); } }); #endif return PurchaseProcessingResult.Complete; }