Present flows in Observer mode in Capacitor SDK
If you use Observer mode, you are responsible for your own purchase logic. But you can delegate the paywall UI to the Flow & Paywall Builder.
Design the screen in the builder, and the Adapty SDK renders it natively. Update its copy, layout, and pricing whenever you want, without an app release.
This guide shows how to present a flow and handle the purchase callbacks. If Adapty completes purchases for you, see Display flows & paywalls instead.
Before you start
You need:
- Adapty Capacitor SDK 4.1 or later: Earlier versions can’t render flows. To move an existing app, see the migration guide.
observerModeset totrue: See the Capacitor SDK installation guide.- Initial store integration: Set up Adapty with the App Store and with Google Play.
- A published flow with products: Build it in the Flow & Paywall Builder and assign products to it.
- A flow placement: Create a placement and assign your flow to it.
- The flow fetched in your app: Get the flow and its configuration before you present it.
Implementation
In Observer mode, the SDK does not make purchases for you. When a user taps the purchase or restore button in an Adapty-rendered flow, the SDK invokes your onObserverPurchaseInitiated or onObserverRestoreInitiated event handler instead. Perform the purchase or restore with your own code there.
-
Set the observer-mode event handlers on the view. Unlike other platforms, there is no separate resolver object — the handlers are part of the regular event handlers, so set them on every view you create:
import { adapty, createFlowView } from '@adapty/capacitor'; const view = await createFlowView(flow); const unsubscribe = await view.setEventHandlers({ onObserverPurchaseInitiated(product, onStartPurchase, onFinishPurchase) { onStartPurchase(); // the view shows its loading indicator myPurchaseApi(product.vendorProductId) .then((transactionId) => adapty.reportTransaction({ transactionId, variationId: flow.variationId }), ) .finally(() => onFinishPurchase()); // the view hides the loading indicator return false; // keep the flow open; dismiss it yourself after success }, onObserverRestoreInitiated(onStartRestore, onFinishRestore) { onStartRestore(); myRestoreApi().finally(() => onFinishRestore()); return false; }, });The
onObserverPurchaseInitiatedhandler informs you that the user has initiated a purchase, andonObserverRestoreInitiated— that the user has initiated a restore. Trigger your custom purchase or restore flow in response.Also, remember to invoke the following callbacks to notify AdaptyUI about the process of the purchase or restore. This is necessary for proper flow behavior, such as showing the loader, among other things:
Callback Description onStartPurchase() The callback should be invoked to notify AdaptyUI that the purchase is started. onFinishPurchase() The callback should be invoked to notify AdaptyUI that the purchase is finished. onStartRestore() The callback should be invoked to notify AdaptyUI that the restore is started. onFinishRestore() The callback should be invoked to notify AdaptyUI that the restore is finished. -
Present the flow view as usual: fetch the flow and create its view, then present it. No extra parameters are needed — the handlers fire only when the SDK was activated with
observerMode: true.
Don’t forget to report the transaction and associate it with the paywall. Otherwise, Adapty will not recognize the transaction and will not determine the source paywall of the purchase.