以下是我们在 I/O 大会上宣布的所有内容,从新的 Firebase Studio 功能到集成 AI 的更多方式,内容非常丰富。
阅读博客。
Misurare gli acquisti in-app
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Gli acquisti in-app (IAP) sono contenuti o funzionalità digitali che puoi vendere in un'app per dispositivi mobili tramite Google Play o l'Apple App Store, in modo che questa non debba elaborare transazioni finanziarie. Esempi di acquisti in-app includono
contenuti su abbonamento o elementi di gioco speciali.
Analytics mostra gli eventi IAP nel
report Acquisti in-app.
Per le app per Android, l'SDK Analytics si integra con Google Play. Per le app della piattaforma Apple, l'SDK si integra con l'Apple App Store utilizzando le API StoreKit 1 e StoreKit 2 di Apple.
Nella maggior parte dei casi, l'SDK Analytics raccoglie automaticamente gli eventi IAP senza
richiedere chiamate API nella tua app. Questa guida spiega come configurare il progetto
per il monitoraggio automatico e descrive alcuni casi speciali che richiedono alcune
righe di codice da implementare.
Prima di iniziare
Se stai sviluppando un'app per Android, puoi misurare gli eventi IAP non appena
esegui il collegamento a Google Play. Il resto di questa guida è incentrato sulle app per la piattaforma Apple.
Se sei uno sviluppatore Apple, assicurati di conoscere le API per gli acquisti in-app StoreKit 1 e StoreKit 2 di Apple consultando la documentazione Apple.
Implementazione
Swift
Se utilizzi StoreKit 1, l'SDK Analytics registra automaticamente
gli eventi IAP.
Se utilizzi StoreKit 2, utilizza il seguente codice per registrare gli eventi IAP.
import StoreKit
import FirebaseAnalytics
// A user tapped a button to purchase an item.
func userTappedPurchaseUpgradeButton() {
let product = ...
purchaseSomeProduct(product)
}
func purchaseSomeProduct(_ product: Product) {
// Purchase a Product. This is mostly standard boilerplate StoreKit 2
// code, except for the Analytics.logTransaction() call.
let result = try await product.purchase()
switch result {
case .success(let verification):
let transaction = try checkVerified(verification)
// Call this Firebase API to log the in-app purchase event.
Analytics.logTransaction(transaction)
await transaction.finish()
...
}
Objective-C
Se utilizzi StoreKit 1, l'SDK Analytics registra automaticamente
gli eventi IAP.
StoreKit 2 è solo Swift, quindi un'implementazione Objective-C non è supportata.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-16 UTC.
[null,null,["Ultimo aggiornamento 2025-08-16 UTC."],[],[],null,["In-app purchases (IAP) are digital content or features that you can sell in a\nmobile app through Google Play or the Apple App Store so your app doesn't\nhave to process financial transactions. Examples of in-app purchases include\nsubscription-based content or special game pieces.\n\nAnalytics shows IAP events in the\n[In-app purchases report](https://support.google.com/analytics/answer/12923440).\n\nFor Android apps, the Analytics SDK integrates with Google Play. For Apple\nplatform apps, the SDK integrates with the Apple App Store using the\nStoreKit 1 and StoreKit 2 APIs from Apple.\n\nIn most cases, the Analytics SDK automatically collects IAP events without\nrequiring API calls in your app. This guide explains how to set up your project\nfor automatic tracking, and it describes some special cases that require a few\nlines of code to implement.\n\nBefore you begin\n\n- Set up your Firebase project and your app's codebase as described in\n [Get Started with Google Analytics](/docs/analytics/get-started).\n\n- [Link your Firebase project to a Google Analytics 4 property.](https://support.google.com/firebase/answer/9289399)\n\n- For Apple platform apps:\n\n - Make sure that your app is using the Analytics SDK v6.20.0+.\n- For Android apps:\n\n - Make sure that your app is using the Analytics SDK v17.3.0+ (or Firebase Android BoM v25.2.0+).\n - [Link your Firebase apps to Google Play](https://support.google.com/firebase/answer/6392038).\n\nIf you're developing an Android app, you can measure IAP events as soon as you\nlink to Google Play. The remainder of this guide is focused on Apple platform\napps.\n\nIf you're an Apple developer, make sure you're familiar with the Apple StoreKit\n1 and StoreKit 2 in-app purchase APIs by reviewing the\n[Apple documentation](https://developer.apple.com/documentation/storekit/in-app_purchase).\n\nImplementation \n\nSwift\n\nIf you're using StoreKit 1, the Analytics SDK automatically logs\nIAP events.\n\nIf you're using StoreKit 2, use the following code to log IAP events. \n\n```swift\nimport StoreKit\nimport FirebaseAnalytics\n\n// A user tapped a button to purchase an item.\nfunc userTappedPurchaseUpgradeButton() {\n let product = ...\n purchaseSomeProduct(product)\n}\n\nfunc purchaseSomeProduct(_ product: Product) {\n // Purchase a Product. This is mostly standard boilerplate StoreKit 2\n // code, except for the Analytics.logTransaction() call.\n let result = try await product.purchase()\n switch result {\n case .success(let verification):\n let transaction = try checkVerified(verification)\n\n // Call this Firebase API to log the in-app purchase event.\n Analytics.logTransaction(transaction)\n\n await transaction.finish()\n ...\n}\n```\n\nObjective-C\n\nIf you're using StoreKit 1, the Analytics SDK automatically logs\nIAP events.\n\nStoreKit 2 is Swift-only, so an Objective-C implementation is not supported.\n\nKotlin\n\nTo log IAP events,\n[link to Google Play](//support.google.com/firebase/answer/6392038).\n\nJava\n\nTo log IAP events,\n[link to Google Play](//support.google.com/firebase/answer/6392038)."]]