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?