背景:
在FaceBook没有验证苹果收据的权限情况下如何区分订阅试用,订阅付费和内购行为并完成自动打点的?
苹果购买行为(包括内购商品和订阅商品)底层逻辑:
1、通过商品id查询商品实例
2、通过商品实例唤起购买并订阅支付事务观察者 SKPaymentTransactionObserver 就可以收到购买结果
FaceBook SDK源码解析开始:
主要逻辑:FaceBook SDK 也订阅了付事务观察者 SKPaymentTransactionObserver 所以它也能收到购买行为。再结合事务中的商品Id参数去查询商品实例结合商品的属性和订单信息来完逻辑判断并打点的
核心方法位置: FBSDKCoreKit->Core->FBSDKPaymentObserver->
if (@available(iOS 11.2, *)) {
if ([self isSubscription:product]) {
// subs inapp
eventParameters[FBSDKAppEventParameterNameSubscriptionPeriod] = [self durationOfSubscriptionPeriod:product.subscriptionPeriod];
eventParameters[FBSDKAppEventParameterNameInAppPurchaseType] = @"subs";
eventParameters[FBSDKAppEventParameterNameIsStartTrial] = [self isStartTrial:transaction ofProduct:product] ? @"1" : @"0";
// trial information for subs
SKProductDiscount *discount = product.introductoryPrice;
if (discount) {
if (discount.paymentMode == SKProductDiscountPaymentModeFreeTrial) {
eventParameters[FBSDKAppEventParameterNameHasFreeTrial] = @"1";
} else {
eventParameters[FBSDKAppEventParameterNameHasFreeTrial] = @"0";
}
eventParameters[FBSDKAppEventParameterNameTrialPeriod] = [self durationOfSubscriptionPeriod:discount.subscriptionPeriod];
eventParameters[FBSDKAppEventParameterNameTrialPrice] = discount.price;
}
} else {
eventParameters[FBSDKAppEventParameterNameInAppPurchaseType] = @"inapp";
}
}
网友评论