Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-app purchase tracking with Google Analytics iOS SDK

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:

  1. 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?
  2. 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?
like image 781
hpique Avatar asked Dec 08 '12 18:12

hpique


2 Answers

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.

like image 70
hpique Avatar answered Sep 20 '22 15:09

hpique


Good question, shame you've got no answers to this as I've just come up against the same issue.

So to stimulate discussion on this topic I'd like to suggest this "workaround".

NSString *affiliation = [product.priceLocale objectForKey:NSLocaleCurrencyCode];  
GAITransaction *gaiTransaction = [GAITransaction transactionWithId:transactionIdentifier withAffiliation:affiliation];

The idea being that you can't do anything about different currencies in-App. Instead you need to move the problem to Analytics and use it's filtering to work out earnings per national App Store.

So if it's a US transaction the affiliate will be "USD".

As for

take Apple's cut into account, which is not always 30%

this is news to me. I was of the impression the 30% was set in stone by Apple. So I'm just multiplying revenue by 0.7

like image 41
Seoras Avatar answered Sep 20 '22 15:09

Seoras