Guides
GuidesLog In
Guides

Observer Mode

If you have a purchase system and/or want to test Apphud without full integration, you can use Observer mode.

Observer Mode

If you are planning to use your own purchase code, consider integrating Apphud SDK in Observer (Analytics) mode. In this case you are responsible for displaying products, making purchases and finishing / acknowleding transactions, and Apphud SDK will only track successful purchases.

❗️

Important Note

Keep in mind, that you are responsible for acknowledging or consuming all purchases on Android, and finishing transactions on iOS while using Apphud SDK in Observer mode.

Apphud.start(apiKey: "YOUR_API_KEY", observerMode: true)

// after making a purchase using StoreKit2, call restorePurchases
// method before finishing a transaction
await Apphud.restorePurchases()
await transaction.finish()
[Apphud startWithApiKey:@"YOUR_API_KEY" userID:nil observerMode:YES];
// Initialization on Android doesn't differ
Apphud.start(this, "YOUR_API_KEY")
await Apphud.start(apiKey: "YOUR_API_KEY", observerMode: true);
await ApphudSdk.start({ apiKey: "YOUR_API_KEY", observerMode: true });

iOS

When initializing the SDK, pass the observerMode: true parameter. For StoreKit1 purchases, the Apphud SDK automatically collects all purchase data. However, for StoreKit2, this is not possible.

For StoreKit2, you must manually submit purchases:

// After making a purchase using StoreKit2, call restorePurchases
// before finishing the transaction
await Apphud.restorePurchases()
await transaction.finish()

Android

Initialization on Android is the same as non-observer mode. See this guide for details.
However, you are responsible for submitting purchases to Apphud after successful purchase and restore.
To track successful purchase call:

Apphud.trackPurchase(purchase, productDetails, offerIdToken)

📘

Missing "trackPurchases" method?

Apphud.trackPurchases() method is new, so if your SDK version is missing it, consider calling Apphud.syncPurchases instead. Or update to the latest SDK version.

Next, when user taps on "Restore Purchases" button in your app's UI, consider calling syncPurchases method:

Apphud.syncPurchases()
await Apphud.syncPurchases();
await ApphudSdk.syncPurchases();

Pass Obfuscated Account ID (Android)

It is highly recommended to set up obfuscatedAccountId in BillingFlowParams object:

BillingFlowParams.newBuilder().setObfuscatedAccountId(Apphud.deviceId())

📘

Note

Don't forget to set up the App Store / Google server notifications in Apphud settings in order to get real time updates.

Observer Mode vs Full Mode: Features Comparison

AdvantagesObserver ModeFull Mode
IntegrationsYes*Yes*
AnalyticsYesYes
Paywalls managementNoYes
Experiments (A/B Tests)Yes***Yes
Rules (iOS)Yes**Yes**
Web2AppYesYes

* requires few more lines of code, like User ID Matching. See documentation of your integration.
** requires push notification handling. See here.
*** requires additional client functions.

A/B Experiments in Observer Mode

If you want to use A/B experiments while running SDK in Observer Mode you should manually send paywall identifier to Apphud using this method. See code example below regarding where to call this method.

// You must call this method right before your own purchase method.
Apphud.willPurchaseProductFromPaywall("main_paywall")
// Your purchase flow
// Call this method with Paywall Identifier right after successful purchase
Apphud.trackPurchase(purchase, details, paywallIdentifier)  
// If trackPurchase is missing in your SDK version, update the SDK or call:
// Apphud.syncPurchases(paywallIdentifier: "your_paywall_identifier")
await Apphud.syncPurchases(paywallIdentifier: "main_paywall")