In-App Purchase
An in_app_purchase event example focused on Android and iOS Firebase implementations.
DataLayer Example
- Android Firebase (Kotlin)
- Android Firebase (Java)
- iOS Firebase (Swift)
- iOS Firebase (Obj-C)
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.IN_APP_PURCHASE) {
param(FirebaseAnalytics.Param.PRODUCT_ID, "sku_premium")
param(FirebaseAnalytics.Param.PRODUCT_NAME, "Premium Plan")
param(FirebaseAnalytics.Param.CURRENCY, "USD")
param(FirebaseAnalytics.Param.VALUE, 9.99)
param(FirebaseAnalytics.Param.SUBSCRIPTION, 1L)
param(FirebaseAnalytics.Param.FREE_TRIAL, 0L)
param(FirebaseAnalytics.Param.PRICE_IS_DISCOUNTED, 1L)
}
Bundle eventParams = new Bundle();
eventParams.putString(FirebaseAnalytics.Param.PRODUCT_ID, "sku_premium");
eventParams.putString(FirebaseAnalytics.Param.PRODUCT_NAME, "Premium Plan");
eventParams.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
eventParams.putDouble(FirebaseAnalytics.Param.VALUE, 9.99);
eventParams.putLong(FirebaseAnalytics.Param.SUBSCRIPTION, 1L);
eventParams.putLong(FirebaseAnalytics.Param.FREE_TRIAL, 0L);
eventParams.putLong(FirebaseAnalytics.Param.PRICE_IS_DISCOUNTED, 1L);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.IN_APP_PURCHASE, eventParams);
var eventParams: [String: Any] = [
AnalyticsParameterProductID: "sku_premium",
AnalyticsParameterProductName: "Premium Plan",
AnalyticsParameterCurrency: "USD",
AnalyticsParameterValue: 9.99,
AnalyticsParameterSubscription: 1,
AnalyticsParameterFreeTrial: 0,
AnalyticsParameterPriceIsDiscounted: 1
]
Analytics.logEvent(AnalyticsEventInAppPurchase, parameters: eventParams)
NSMutableDictionary *eventParams = [@{
kFIRParameterProductID: @"sku_premium",
kFIRParameterProductName: @"Premium Plan",
kFIRParameterCurrency: @"USD",
kFIRParameterValue: @(9.99),
kFIRParameterSubscription: @(1),
kFIRParameterFreeTrial: @(0),
kFIRParameterPriceIsDiscounted: @(1)
} mutableCopy];
[FIRAnalytics logEventWithName:kFIREventInAppPurchase parameters:eventParams];
Event Properties
| Property | Type | Constraints | Examples | Description |
|---|---|---|---|---|
| $schema | string | required | | Defines the structure of the event. |
const: "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/mobile/in-app-purchase-event.json" | ||||
| event | string | required | | The event name for an in-app purchase. |
const: "in_app_purchase" | ||||
| product_id | string | required | | The purchased product identifier. |
| product_name | string | required | | Display name of the purchased product. |
| currency | string | required | | ISO 4217 currency code. |
minLength: 3 | ||||
maxLength: 3 | ||||
| value | number | required | | Purchase value. |
| subscription | boolean | | Whether the purchase is a subscription. | |
| free_trial | boolean | | Whether a free trial was used. | |
| price_is_discounted | boolean | | Whether the listed price is discounted. | |
additionalPropertiesSchema constraintControls properties not listed in properties and not matched by patternProperties. | string, number, integer, boolean, null |
View Raw JSON Schema
{
: "https://json-schema.org/draft/2020-12/schema",
: "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/mobile/in-app-purchase-event.json",
"title": "In-App Purchase",
"description": "An in_app_purchase event example focused on Android and iOS Firebase implementations.",
"x-tracking-targets": [
"android-firebase-kotlin-sdk",
"android-firebase-java-sdk",
"ios-firebase-swift-sdk",
"ios-firebase-objc-sdk"
],
"type": "object",
"properties": {
"$schema": {
"type": "string",
"description": "Defines the structure of the event.",
"const": "https://tracking-docs-demo.buchert.digital/schemas/1.3.0/mobile/in-app-purchase-event.json"
},
"event": {
"type": "string",
"const": "in_app_purchase",
"description": "The event name for an in-app purchase."
},
"product_id": {
"type": "string",
"description": "The purchased product identifier.",
"examples": [
"sku_premium"
]
},
"product_name": {
"type": "string",
"description": "Display name of the purchased product.",
"examples": [
"Premium Plan"
]
},
"currency": {
"type": "string",
"description": "ISO 4217 currency code.",
"minLength": 3,
"maxLength": 3,
"examples": [
"USD"
]
},
"value": {
"type": "number",
"description": "Purchase value.",
"examples": [
9.99
]
},
"subscription": {
"type": "boolean",
"description": "Whether the purchase is a subscription.",
"examples": [
true
]
},
"free_trial": {
"type": "boolean",
"description": "Whether a free trial was used.",
"examples": [
false
]
},
"price_is_discounted": {
"type": "boolean",
"description": "Whether the listed price is discounted.",
"examples": [
true
]
}
},
"required": [
"$schema",
"event",
"product_id",
"product_name",
"currency",
"value"
],
"allOf": [
{
"$ref": "https://tracking-docs-demo.buchert.digital/constraints/schemas/firebase/v1/flat-event-params.json"
}
]
}