gpt4 book ai didi

ios - Google Analytics - 获取 iOS 应用内购买值(value)

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:38 24 4
gpt4 key购买 nike

我跟随 this tutorial 在我的 iOS 应用中成功实现了应用内购买。

我现在正尝试使用以下代码实现 Google Analytics 来跟踪购买情况。但在成功完成购买后,我不确定从哪里获取实际值。

任何示例代码将不胜感激。

- (void)onPurchaseCompleted {
GAITransaction *transaction =
[GAITransaction transactionWithId:@"0_123456" // (NSString) Transaction ID, should be unique.
withAffiliation:@"In-App Store"]; // (NSString) Affiliation
transaction.taxMicros = (int64_t)(0.17 * 1000000); // (int64_t) Total tax (in micros)
transaction.shippingMicros = (int64_t)(0); // (int64_t) Total shipping (in micros)
transaction.revenueMicros = (int64_t)(2.16 * 1000000); // (int64_t) Total revenue (in micros)

[transaction addItemWithSKU:@"L_789" // (NSString) Product SKU
name:@"Level Pack: Space" // (NSString) Product name
category:@"Game expansions" // (NSString) Product category
priceMicros:(int64_t)(1.99 * 1000000) // (int64_t) Product price (in micros)
quantity:1]; // (NSInteger) Product quantity

[[GAI sharedInstance].defaultTracker sendTransaction:transaction]; // Send the transaction.
}

最佳答案

这是我的最终代码:

- (void)trackPurchaseWithTransaction:(SKPaymentTransaction *)transaction andAction:(NSString *)action
{
//Only track purchase, not restore
if(![action isEqualToString:IAPHelperProductPurchasedNotification]) return;

id tracker = [[GAI sharedInstance] defaultTracker];

SKPayment *payment = transaction.payment;
NSString *sku = payment.productIdentifier;
SKProduct *product;

for(SKProduct *skProduct in skProducts) {
if([skProduct.productIdentifier isEqualToString:skProduct.productIdentifier]) {
product = skProduct;
}
}

NSLocale *priceLocale = product.priceLocale;
NSString *currencyCode = [priceLocale objectForKey:NSLocaleCurrencyCode];
NSString *transactionId = transaction.transactionIdentifier;
NSNumber *productPrice = product.price;
NSNumber *revenue = @(productPrice.floatValue * payment.quantity);

GAIDictionaryBuilder *transBuilder = [GAIDictionaryBuilder createTransactionWithId:transactionId
affiliation:@"App Store"
revenue:revenue
tax:0
shipping:0
currencyCode:currencyCode];
[tracker send:[transBuilder build]];

GAIDictionaryBuilder *itemBuilder = [GAIDictionaryBuilder createItemWithTransactionId:transactionId
name:product.localizedTitle
sku:sku
category:@"In-App Purchase"
price:productPrice
quantity:@(payment.quantity)
currencyCode:currencyCode];
[tracker send:[itemBuilder build]];
}

关于ios - Google Analytics - 获取 iOS 应用内购买值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com