使用Google Analytics iOS SDK进行应用内购买跟踪 [英] In-app purchase tracking with Google Analytics iOS SDK

查看:133
本文介绍了使用Google Analytics iOS SDK进行应用内购买跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用Google AnalyticsSDK for iOS v2跟踪应用内购买,如 SKPaymentTransactionStatePurchased 之后,我正在执行以下操作:

事务更新:

   - (void)trackTransaction:(SKPaymentTransaction *)transaction 
{
NSString * transactionIdentifier = transaction.transactionIdentifier;
GAITransaction * gaiTransaction = [GAITransaction transactionWithId:transactionIdentifier withAffiliation:@App Store];

SKPayment *付款= transaction.payment;
NSString * productIdentifier = payment.productIdentifier;
SKProduct * product = [self productForIdentifier:productIdentifier];
NSString * productTitle = product.localizedTitle;
int64_t priceInMicros = product.price.floatValue * 1000000; // FIXME:不考虑不同货币
[gaiTransaction addItemWithCode:productIdentifier name:productTitle category:nil priceMicros:priceInMicros quantity:payment.quantity];

gaiTransaction.revenueMicros = priceInMicros * payment.quantity; // FIXME:不考虑苹果的减价

id< GAITracker> tracker = [GAI sharedInstance] .defaultTracker;
[tracker trackTransaction:gaiTransaction];
}

以上是追踪应用内购买的正确方法吗?我至少检测到两个问题:


  1. SKProduct 会返回一个本地化的价格,如果我将它作为收入汇总将是不正确的。有没有办法使价格正常化?

  2. 返回的收入不会考虑苹果公司的削减,这并不总是30%。

  3. 解决方案


    是否可以在应用程序中获得净收入? 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:

    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?

    解决方案

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆