hpi*_*que 13 iphone google-analytics storekit in-app-purchase ios
我想按照其电子商务跟踪指南中的说明,使用Google Analytics SDK for iOS v2跟踪应用内购买情况.
我在收到SKPaymentTransactionStatePurchased事务更新后正在执行以下操作:
- (void) trackTransaction:(SKPaymentTransaction*)transaction
{
NSString *transactionIdentifier = transaction.transactionIdentifier;
GAITransaction *gaiTransaction = [GAITransaction transactionWithId:transactionIdentifier withAffiliation:@"App Store"];
SKPayment *payment = transaction.payment;
NSString *productIdentifier = payment.productIdentifier;
SKProduct *product = [self productForIdentifier:productIdentifier];
NSString *productTitle = product.localizedTitle;
int64_t priceInMicros = product.price.floatValue * 1000000; // FIXME: Doesn't consider different currencies
[gaiTransaction addItemWithCode:productIdentifier name:productTitle category:nil priceMicros:priceInMicros quantity:payment.quantity];
gaiTransaction.revenueMicros = priceInMicros * payment.quantity; // FIXME: doesn't consider Apple's cut
id<GAITracker> tracker = [GAI sharedInstance].defaultTracker;
[tracker trackTransaction:gaiTransaction];
}
Run Code Online (Sandbox Code Playgroud)
以上是跟踪应用内购买的正确方法吗?我至少发现了两个问题:
SKProduct返回本地化价格,如果我跟踪它,收入汇总将是不正确的.有没有办法规范价格?hpi*_*que 11
SKProduct返回本地化价格,如果我跟踪它,收入汇总将是不正确的.有没有办法规范价格?
Google Analytics SKD for iOS v3增加了对货币的支持.跟踪事务如下所示:
- (void)storePaymentTransactionFinished:(NSNotification *)notification
{
SKPaymentTransaction *paymentTransaction = notification.transaction;
if (paymentTransaction.transactionState == SKPaymentTransactionStateRestored) return;
SKPayment *payment = paymentTransaction.payment;
NSString *sku = payment.productIdentifier;
SKProduct *product = [[RMStore defaultStore] productForIdentifier:sku];
NSLocale *priceLocale = product.priceLocale;
NSString *currencyCode = [priceLocale objectForKey:NSLocaleCurrencyCode];
NSString *transactionId = paymentTransaction.transactionIdentifier;
NSNumber *productPrice = product.price;
{
NSNumber *revenue = @(productPrice.floatValue * payment.quantity);
GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createTransactionWithId:transactionId
affiliation:@"App Store"
revenue:revenue
tax:0
shipping:0
currencyCode:currencyCode];
NSDictionary *parameters = [builder build];
[_tracker send:parameters];
}
{
GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createItemWithTransactionId:transactionId
name:product.localizedTitle
sku:sku
category:@"In-App Purchase"
price:productPrice
quantity:@(payment.quantity)
currencyCode:currencyCode];
NSDictionary *parameters = [builder build];
[_tracker send:parameters];
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码使用RMStore来方便.
退回的收入并没有考虑Apple的削减,这并不总是30%.是否有可能获得应用程序内的净收入?
没有.
| 归档时间: |
|
| 查看次数: |
4338 次 |
| 最近记录: |