Respectlytics Respect lytics
Menu
Flutter In-app purchase Privacy-first

How to track in-app purchases in Flutter without personal data

In-app purchase is the bread-and-butter event of mobile games and content apps. Most analytics SDKs treat it as a per-user revenue event with SKU, price, currency, and transaction ID. Respectlytics helps developers avoid collecting personal data in the first place: in Flutter, IAP is one named event when a transaction succeeds, with no metadata. Revenue accounting lives in your billing system. Below: the Flutter pattern, the difference between consumable and non-consumable purchases, and the metadata trade-offs.

Wire the call into the success branch of your StoreKit / Billing transaction handler. Use distinct event names per purchase category if you want to differentiate consumables from non-consumables (iap_consumable, iap_nonconsumable). Don't pass the SKU, price, or transaction ID.

Install the Flutter SDK

yaml Respectlytics
# pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
  respectlytics_flutter: ^3.0.0

Pure Dart — no platform channels for analytics. Same code on every platform Flutter compiles to (iOS, Android, web, macOS, Windows, Linux). On web, events are sent via the REST API; mobile platforms use the same path.

Initialize Respectlytics in Flutter

dart Respectlytics
import 'package:flutter/material.dart';
import 'package:respectlytics_flutter/respectlytics_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Respectlytics.configure(appKey: '<YOUR_APP_KEY>');
  runApp(const MyApp());
}

Initialize in main() after WidgetsFlutterBinding.ensureInitialized() and before runApp(). The future completes immediately on configuration; events queued before completion are flushed once the network is available.

Track the event in Flutter

dart Respectlytics
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:respectlytics_flutter/respectlytics_flutter.dart';

const consumableSkus = {'gold_pack_small', 'gold_pack_large'};

void onPurchaseUpdate(List<PurchaseDetails> purchases) {
  for (final purchase in purchases) {
    if (purchase.status != PurchaseStatus.purchased) continue;
    final isConsumable = consumableSkus.contains(purchase.productID);
    Respectlytics.track(isConsumable ? 'iap_consumable' : 'iap_nonconsumable');
    InAppPurchase.instance.completePurchase(purchase);
  }
}

On Android, you must additionally call consumePurchase for consumables — that's a Billing Library requirement separate from analytics. Don't skip it.

Privacy & implementation notes

Consumables (a single in-game gold pack) and non-consumables (a one-time premium upgrade) have very different product implications: consumables drive ARPU directly, non-consumables drive long-term retention. Mixing them under one iap event hides the most useful breakdown.

Always finish the transaction with the platform billing API after firing the analytics event — not before. If your track call were to throw (it doesn't, but defensively), you'd want the platform to keep its retry behavior. Respectlytics's track is a fire-and-forget call into a RAM queue; it never blocks transaction completion.

The Flutter SDK is pure Dart. No MethodChannel, no platform-specific iOS or Android plugin code. The same code runs on every platform Flutter supports — including web and desktop targets. This eliminates one common audit surface ("what's the Android implementation doing?").

Always initialize after WidgetsFlutterBinding.ensureInitialized() and before runApp(). If you skip the binding step, the configure call will throw on platforms that need a binding for asynchronous I/O. The SDK documentation example uses this pattern by default.

How this compares to other analytics SDKs

In-app purchase eventFirebase AnalyticsMixpanelRespectlytics
SKU storedRecommendedRecommendedUse distinct event_name
Price / currency storedRecommendedRecommendedRejected by API
Transaction ID storedYesYesRejected by API
Per-user spend totalYesYesUse billing system
Purchase *rate* by country / platformYesYesYes (default)

Frequently asked questions

How do we differentiate consumables from non-consumables?

Distinct event names: iap_consumable, iap_nonconsumable, optionally iap_subscription for subscriptions. Don't embed the type as a parameter — the API rejects parameters.

What about lifetime spend per user?

Out of scope for Respectlytics. Your billing system or RevenueCat already computes lifetime spend per user, with authoritative timestamps and refund-aware totals. Asking your product analytics to do this duplicates a system of record and produces drift.

Do we differentiate purchases by SKU at all?

Only if a SKU breakdown is genuinely actionable for product decisions, and only via distinct event names: iap_gold_pack, iap_starter_bundle. Keep the set small — under 10 SKUs is fine; past that, bucket the long tail.

Should we fire on purchase initiation or completion?

Completion. Initiation-fire inflates the event count with abandoned platform billing prompts. The transaction observer's .purchased state is the right hook.

Related guides

Track what matters. Collect nothing you don't.

Five-field event schema, RAM-only event queue, no IDFA, no AAID, no persistent user IDs. Helps developers avoid collecting personal data in the first place.