Associate paywalls to purchase transactions in Observer mode

Learn how to link a purchase transaction with its source paywall

In Observer mode, Adapty SDK cannot determine the source of purchases as you are the one processing them. Therefore, if you intend to use paywalls and/or A/B tests in Observer mode, you need to associate the transaction coming from your app store with the corresponding paywall in your mobile app code. This is important to get right before releasing your app, otherwise it will lead to errors in analytics.

After the preliminary configuration is done, you need to associate the transaction generated by Apple or Google to the corresponding paywall in your mobile app code using the variationId parameter as shown in the example below. Make sure you always associate the transaction with the paywall that generated it, only then you will be able to see the correct metrics in the Adapty Dashboard.

let variationId = paywall.variationId

// There are two overloads: for StoreKit 1 and StoreKit 2
Adapty.setVariationId(variationId, forPurchasedTransaction: transaction) { error in
    if error == nil {
        // successful binding
    }    
}
Adapty.setVariationId(transactionId, variationId) { error ->
    if (error == null) {
        // success
    }
}
Adapty.setVariationId(transactionId, variationId, error -> {
    if (error == null) {
        // success
    }
});
final transactionId = transaction.transactionIdentifier
final variationId = paywall.variationId

try {
  await Adapty().setVariationId('transaction_id', variationId);
} on AdaptyError catch (adaptyError) {
  // handle the error
} catch (e) {
}
const variationId = paywall.variationId;

try {
	await adapty.setVariationId('transaction_id', variationId);
} catch (error) {
	// handle the `AdaptyError`
}
Adapty.SetVariationForTransaction("<variationId>", "<transactionId>", (error) => { 
    if(error != null) {
        // handle the error
        return;
    }

    // successful binding
});

Request parameters:

ParameterPresenceDescription
variationIdrequiredThe string identifier of the variation. You can get it using variationId property of the AdaptyPaywall object.
transactionrequiredFor iOS, StoreKit1: an SKPaymentTransaction object.
For iOS, StoreKit 2: Transaction object.
For Android: String identifier (purchase.getOrderId()) of the purchase, where the purchase is an instance of the billing library Purchase class.

For accurate analytics, ensure the transaction is associated with the paywall within 3 hours of its creation.