使用Google Analytics iOS SDK进行应用内购买跟踪 [英] In-app purchase tracking with Google Analytics iOS SDK
问题描述
是否可以在应用程序中获得净收入? SKProduct返回一个本地化的价格,如果我将它作为收入追踪
聚合将是不正确的。有没有办法使价格正常化?
Google Analytics SKD for iOS v3 增加了对货币的支持。跟踪交易如下所示:
- (void)storePaymentTransactionFinished:(NSNotification *)notification
{
SKPaymentTransaction * paymentTransaction = notification.transaction;
if(paymentTransaction.transactionState == SKPaymentTransactionStateRestored)return;
SKPayment *付款= 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 *收入= @(productPrice.floatValue * payment.quantity);
GAIDictionaryBuilder * builder = [GAIDictionaryBuilder createTransactionWithId:transactionId
从属关系:@App Store
收入:收入
税:0
运费:0
currencyCode :货币代码];
NSDictionary *参数= [builder build];
[_tracker send:parameters];
}
{
GAIDictionaryBuilder * builder = [GAIDictionaryBuilder createItemWithTransactionId:transactionId
name:product.localizedTitle
sku:sku
category:@In-App购买
价格:productPrice
数量:@(payment.quantity)
currencyCode:currencyCode];
NSDictionary *参数= [builder build];
[_tracker send:parameters];
$ b上面的代码使用 RMStore 为方便起见。
不考虑苹果公司的削减,这是
并不总是30%。是否有可能在
应用程序内获得净收入?
否。
I would like to track in-app purchases with the Google Analytics SDK for iOS v2, as indicated in their Ecommerce Tracking guide.
I'm currently doing the following after receiving a SKPaymentTransactionStatePurchased
transaction update:
- (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];
}
Is the above the right way of tracking in-app purchases? I detect two problems at the very least:
SKProduct
returns a localized price and if I track it as-is revenue aggregation will be incorrect. Is there a way to normalize the price?
- The revenue returned doesn't take Apple's cut into account, which is not always 30%. Is it possible to obtain the net revenue within the app?
解决方案
SKProduct returns a localized price and if I track it as-is revenue
aggregation will be incorrect. Is there a way to normalize the price?
Google Analytics SKD for iOS v3 added support for currencies. Tracking a transaction looks like this:
- (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];
}
}
The above code uses RMStore for convenience.
The revenue returned doesn't take Apple's cut into account, which is
not always 30%. Is it possible to obtain the net revenue within the
app?
No.
这篇关于使用Google Analytics iOS SDK进行应用内购买跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!