Purchase Tracking
Track in-app purchases to see revenue data, top products, and ARPPU (Average Revenue Per Paying User) in the dashboard.
Functions
Section titled “Functions”track_purchase()
Section titled “track_purchase()”QuestData.track_purchase(product_id: String, price: float, currency: String = "USD", metadata: Dictionary = {})| Parameter | Type | Default | Description |
|---|---|---|---|
product_id | String | required | Store product identifier (e.g. "starter_pack", "coins_500") |
price | float | required | Purchase price (must be > 0) |
currency | String | "USD" | ISO 4217 currency code (auto-uppercased) |
metadata | Dictionary | {} | Additional data (merged into event properties) |
Sends a purchase_completed event. The SDK validates that product_id is not empty and price is positive.
Example
Section titled “Example”# Basic purchasefunc _on_purchase_confirmed(product: StoreProduct): QuestData.track_purchase(product.id, product.price, product.currency)
# Purchase with metadatafunc _on_iap_completed(product_id: String, receipt: Dictionary): QuestData.track_purchase(product_id, 4.99, "USD", { "store": "google_play", "transaction_id": receipt.get("transaction_id", ""), "first_purchase": not has_purchased_before })
# Virtual currency purchasefunc _on_coins_bought(): QuestData.track_purchase("coins_1000", 2.99, "EUR", { "coins_received": 1000, "bonus_coins": 100 })Subscription Tracking
Section titled “Subscription Tracking”# Battle Pass purchasefunc _on_battle_pass_purchased(): QuestData.track_purchase("battle_pass_s3", 9.99, "USD", { "season": 3, "duration_days": 30, "type": "subscription" })Dashboard
Section titled “Dashboard”View purchase data under Monetization > Revenue:
- Revenue Timeline — Daily/weekly/monthly revenue charts
- Top Products — Best-selling items ranked by revenue
- ARPPU — Average Revenue Per Paying User
- Purchase Count — Number of transactions over time
How It Works
Section titled “How It Works”track_purchase()creates apurchase_completedevent- The
priceandcurrencyare stored as event properties - Any
metadatakeys are merged into the same properties dictionary - The event is queued and batched like any other event
- The backend aggregates revenue data for dashboard display
Best Practices
Section titled “Best Practices”- Track after confirmation — Only call
track_purchase()after the purchase is verified by your store - Use consistent product IDs — Match your store’s product identifiers exactly
- Include currency — Different markets use different currencies; always specify
- Add store metadata — Transaction IDs help reconcile with store dashboards
- Track refunds separately — Use a custom event like
QuestData.track("purchase_refunded", {...})