记录 transaction 事件
Track in-app purchases and failed transactions to measure revenue and monitor transaction health.
阅读时间5 分钟最后更新于 12 天前
使用
transactionProductProductproductsSpentproductsReceivedtransactionFailedtransactiontransactionFailed手动发送事件
transactiontransactionFailed报告成功的购买
在以下示例中,transactiontransactionpublic void SendTransaction(){ var productsReceived = new Product() { Items = new List<Item>() { new Item(){ ItemName = "Golden Battle Axe" , ItemType = "Weapon", ItemAmount = 1}, new Item(){ ItemName = "Flaming Sword" , ItemType = "Weapon", ItemAmount = 1}, new Item(){ ItemName = "Jewel Encrusted Shield" , ItemType = "Armour", ItemAmount = 1} }, VirtualCurrencies = new List<VirtualCurrency>() { new VirtualCurrency() { VirtualCurrencyName = "Gold", VirtualCurrencyType = "PREMIUM", VirtualCurrencyAmount = 100 } } }; var productsSpent = new Product() { RealCurrency = new RealCurrency() { RealCurrencyType = "USD", RealCurrencyAmount = 499 } }; AnalyticsService.Instance.Transaction(new TransactionParameters() { ProductsReceived = productsReceived, ProductsSpent = productsSpent, TransactionID = "100000576198248", TransactionName = "IAP - A Large Treasure Chest", TransactionType = TransactionType.PURCHASE, TransactionServer = TransactionServer.APPLE, TransactionReceipt = "ewok9Ja81............991KS==" });}
报告失败的购买
transactionFailedtransactionFailedtransactionFailedpublic void SendTransactionFailed(){ var productsReceived = new Product() { items = new List<Item>() { new Item(){ ItemName = "Golden Battle Axe" , ItemType = "Weapon", ItemAmount = 1}, new Item(){ ItemName = "Flaming Sword" , ItemType = "Weapon", ItemAmount = 1}, new Item(){ ItemName = "Jewel Encrusted Shield" , ItemType = "Armour", ItemAmount = 1} }, VirtualCurrencies = new List<VirtualCurrency>() { new VirtualCurrency() { VirtualCurrencyName = "Gold", VirtualCurrencyType = "PREMIUM", VirtualCurrencyAmount = 100 } } }; var productsSpent = new Product() { RealCurrency = new RealCurrency() { RealCurrencyType = "USD", RealCurrencyAmount = 499 } }; AnalyticsService.Instance.TransactionFailed(new TransactionFailedParameters { FailureReason = "cancelled", ProductsReceived = productsReceived, ProductsSpent = productsSpent, TransactionID = "100000576198248", TransactionName = "IAP - A Large Treasure Chest", TransactionType = TransactionType.PURCHASE, TransactionServer = TransactionServer.APPLE });}
使用 IAP 插件自动记录
通过 Unity IAP 进行的交易自动转发到 Analytics,使用与手动发送事件时相同的transactiontransactionFailed验证交易
交易验证会检查交易是否为合法购买。 平台可以对 iOS 和 Android 商店进行交易收据验证,以确保后台中显示的任何收入都是真正的收入,而不是游戏被黑客劫持或越狱后的结果。 为了使用交易验证,您需要:- 提供相关商店的验证密钥,以便 Analytics 平台可以针对商店验证收据。您可以在 Dashboard(后台)的 **Project Settings(项目设置)**下执行此操作。
- 在 事件中包含收据验证参数,以便通知平台需要验证交易(这将因商店而异)。
transaction
revenueValidated值 | 结果 |
|---|---|
| 0 | 此交易未使用收入验证服务,包含在您的收入图表中。 |
| 1 | 此交易已通过验证,包含在您的收入图表中。 |
| 2 | 此交易未通过验证,不包含在您的收入图表中。 |
| 3 | 此交易由于错误而无法验证,不包含在您的收入图表中。 |
Apple 商店
Analytics 会自动尝试对 iOS 交易进行收据验证。请将以下代码添加到 iOS 交易以验证收据:"transactionServer": "APPLE","transactionID":"100000576198248","transactionReceipt": "ewok9Ja81............991KS=="
transactionReceipt Google Play
您必须提供 Google 公钥。要更新 Google 密钥,请转到 Project Settings(项目设置)> In-app purchase (IAP) settings(应用内购 (IAP) 设置),然后填充 Google 许可证密钥。 请将以下代码添加到 Android 交易的 transaction 事件中以验证收据:重要:由于交易收据和私钥会生成"transactionServer":"GOOGLE","transactionReceipt":"{ \"orderId\":\"GPA.1234-5678-9012-34567\", \"packageName\":\"com.example.app\", \"productId\":\"exampleSku\", \"purchaseTime\":1345678900000, \"purchaseState\":0, \"developerPayload\":\"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ\", \"purchaseToken\":\"opaque-token-up-to-1000-characters\"}", "transactionReceiptSignature":"rNvoHwiBdLSW+........VncbYVJ61fmfsQ=="
transactionReceiptSignature