以下是我们在 I/O 大会上宣布的所有内容,从新的 Firebase Studio 功能到集成 AI 的更多方式,内容非常丰富。
阅读博客。
خریدهای درون برنامه ای را اندازه گیری کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
خریدهای درونبرنامهای (IAP) محتوا یا ویژگیهای دیجیتالی هستند که میتوانید آنها را در یک برنامه تلفن همراه از طریق Google Play یا Apple App Store بفروشید تا برنامه شما مجبور به پردازش تراکنشهای مالی نباشد. نمونه هایی از خریدهای درون برنامه ای شامل محتوای مبتنی بر اشتراک یا قطعات بازی ویژه است.
Analytics رویدادهای IAP را در گزارش خریدهای درونبرنامه نشان میدهد.
برای برنامههای Android، Analytics SDK با Google Play ادغام میشود. برای برنامههای پلتفرم اپل، SDK با استفاده از StoreKit 1 و StoreKit 2 APIهای اپل با فروشگاه App Apple ادغام میشود.
در بیشتر موارد، Analytics SDK به طور خودکار رویدادهای IAP را بدون نیاز به تماس های API در برنامه شما جمع آوری می کند. این راهنما نحوه راهاندازی پروژه خود را برای ردیابی خودکار توضیح میدهد و موارد خاصی را که برای پیادهسازی به چند خط کد نیاز دارند، توضیح میدهد.
قبل از شروع
اگر در حال توسعه یک برنامه Android هستید، میتوانید رویدادهای IAP را به محض پیوند دادن به Google Play اندازهگیری کنید. بقیه این راهنما بر روی برنامه های پلت فرم اپل متمرکز است.
اگر یک برنامهنویس اپل هستید، با بررسی اسناد اپل مطمئن شوید که با APIهای خرید درونبرنامهای Apple StoreKit 1 و StoreKit 2 آشنا هستید.
پیاده سازی
سویفت
اگر از StoreKit 1 استفاده می کنید، Analytics SDK به طور خودکار رویدادهای IAP را ثبت می کند.
اگر از StoreKit 2 استفاده می کنید، از کد زیر برای ثبت رویدادهای 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()
...
}
هدف-C
اگر از StoreKit 1 استفاده می کنید، Analytics SDK به طور خودکار رویدادهای IAP را ثبت می کند.
StoreKit 2 فقط Swift است، بنابراین پیاده سازی Objective-C پشتیبانی نمی شود.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی."],[],[],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)."]]