我正在使用Unity IAP,如果以前购买过,也会触发ProcessPurchase
。
我的问题是,如果我将收益分析放在该功能中,它将在仪表板上显示重复数据。如何确保我的跟踪设置正确?。
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
bool validPurchase = true;
if (ReceiptSupport)
{
// Presume valid for platforms with no R.V.
// Unity IAP's validation logic is only included on these platforms.
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
// Prepare the validator with the secrets we prepared in the Editor
// obfuscation window.
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
try
{
// On Google Play, result has a single product ID.
// On Apple stores, receipts contain multiple products.
var result = validator.Validate(args.purchasedProduct.receipt);
// For informational purposes, we list the receipt(s)
Debug.Log("Receipt is valid. Contents:");
foreach (IPurchaseReceipt productReceipt in result)
{
//Debug.Log(productReceipt.productID);
//Debug.Log(productReceipt.purchaseDate);
//Debug.Log(productReceipt.transactionID);
GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
if (null != google) {
// This is Google's Order ID.
// Note that it is null when testing in the sandbox
// because Google's sandbox does not provide Order IDs.
Debug.Log(google.productID);
Debug.Log(google.purchaseDate);
Debug.Log(google.purchaseToken);
if (google.purchaseState == GooglePurchaseState.Purchased)
{
Debug.Log("RECORD PURCHASE EVENT ANDROID");
Answers.LogPurchase (
args.purchasedProduct.metadata.localizedPrice,
args.purchasedProduct.metadata.isoCurrencyCode,
(result != null ? true : false),
args.purchasedProduct.metadata.localizedTitle,
args.purchasedProduct.definition.type.ToString(),
args.purchasedProduct.transactionID,
null
);
}
}
AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
if (null != apple) {
Debug.Log(apple.originalTransactionIdentifier);
Debug.Log(apple.subscriptionExpirationDate);
Debug.Log(apple.cancellationDate);
Debug.Log(apple.quantity);
if (apple.originalPurchaseDate == apple.purchaseDate)
Debug.Log("RECORD PURCHASE EVENT IOS");
}
}
}
catch (IAPSecurityException)
{
Debug.Log("Invalid receipt, not unlocking content. SUPER PROBLEM");
validPurchase = false;
}
#endif
}