Observer Mode
Learn how to use Adapty SDK in Observer mode along with existing purchase infrastructure
If you have a functioning subscription system and want to give Adapty SDK a quick try, you can use Observer mode. With just one line of code you can:
- get insights by using our top-class analytics;
- send subscription events to your server and 3rd party services;
- view and analyze customers in Adapty CRM.
Important
When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it.
Activating Observer Mode
Adapty SDK will automatically collect all transactions and will be sending subscription events. To turn on Observer mode, just set observerMode
to true
when activating Adapty.
Android SDK
At any purchase or restore in your application, you need to call .
restorePurchases()
method to record the action in Adapty.
Adapty.activate("PUBLIC_SDK_KEY", customerUserId: "YOUR_USER_ID", observerMode: true)
Adapty.activate(applicationContext, "PUBLIC_SDK_KEY", customerUserId = "YOUR_USER_ID", observerMode = true)
//And at any purchase or restore in your application
Adapty.restorePurchases { purchaserInfo, googleValidationResultList, error ->
if (error == null) {
// successful restore
}
}
// in Info.plist
<dict>
...
<key>AdaptyPublicSdkKey</key>
<string>PUBLIC_SDK_KEY</string>
<key>AdaptyObserverMode</key>
<true/>
</dict>
// in AndroidManifest.xml
<application ...>
...
<meta-data
android:name="AdaptyPublicSdkKey"
android:value="PUBLIC_SDK_KEY"/>
<meta-data
android:name="AdaptyObserverMode"
android:value="true"/>
</application>
import { activateAdapty } from 'react-native-adapty';
const App: React.FC = () => {
...
useEffect(() => {
activateAdapty({
sdkKey: 'PUBLIC_SDK_KEY',
customerUserId: "YOUR_USER_ID",
observerMode: true
});
},[]);
...
}
A/B tests analytics
In Observer mode, Adapty SDK doesn't know, where the purchase was made from. If you display products using our Paywalls or A/B Tests, you can manually assign variation to the purchase. After doing this, you'll be able to see metrics in Adapty Dashboard.
let transactionId = transaction.transactionIdentifier
let variationId = paywall.variationId
Adapty.setVariationId(variationId, forTransactionId: transactionId) { (error) in
if error == nil {
// successful binding
}
}
Adapty.setTransactionVariationId(transactionId, variationId) { error ->
if (error == null) {
// success
}
}
try {
await Adapty.setTransactionVariationId('<transactionId>', '<variationId>');}
on AdaptyError catch (adaptyError) {}
catch (e) {}
const transactionId = transaction.transactionIdentifier;
const variationId = paywall.variationId;
try {
await adapty.purchases.setVariationId(variationId, transactionId);
} catch (error: AdaptyError) {}
Request parameters:
variationId
(required): a string identifier of variation. You can get it usingvariationId
property ofAdaptyPaywall
transactionId
(required): a string identifier of your purchased transactionSKPaymentTransaction
for iOS or a string identifier (purchase.getOrderId()
) of the purchase, where the purchase is an instance of the billing library Purchase class for Android
Updated 21 days ago