简体   繁体   English

使用Google Analytics iOS SDK进行应用内购买跟踪

[英]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. 我想按照其电子商务跟踪指南中的说明,使用Google Analytics SDK for iOS v2跟踪应用内购买情况。

I'm currently doing the following after receiving a SKPaymentTransactionStatePurchased transaction update: 我在收到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];
}

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. SKProduct返回本地化价格,如果我跟踪它,收入汇总将是不正确的。 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%. 退回的收入并没有考虑Apple的削减,这并不总是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. SKProduct返回本地化价格,如果我跟踪它,收入汇总将是不正确的。 Is there a way to normalize the price? 有没有办法规范价格?

Google Analytics SKD for iOS v3 added support for currencies. Google Analytics SKD for iOS v3增加了对货币的支持。 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. 上面的代码使用RMStore来方便。

The revenue returned doesn't take Apple's cut into account, which is not always 30%. 退回的收入并没有考虑Apple的削减,这并不总是30%。 Is it possible to obtain the net revenue within the app? 是否有可能获得应用程序内的净收入?

No. 没有。

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. 相反,您需要将问题移至Google Analytics并使用其过滤来计算每个国家/地区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% 考虑Apple的削减,这并不总是30%

this is news to me. 这对我来说是新闻。 I was of the impression the 30% was set in stone by Apple. 我的印象是,苹果公司30%的成功。 So I'm just multiplying revenue by 0.7 所以我只是将收入乘以0.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM