Skip to main content
Context-specific experiments allow you to track metrics exclusively for purchases made within a specific context. This is useful when you want to measure the impact of a particular screen or flow on conversion rates. When enabled, only purchases that include the experiment’s context key will be counted toward the experiment’s metrics. This gives you more accurate data about how a specific paywall or offer performs. To use context-specific experiments:
  1. Set a Context key when creating the experiment
  2. Enable the Context-specific toggle
  3. Pass the context key when making purchases in your app
Use the following code snippets to pass context keys when making a purchase:
Swift
let purchaseOptions = Qonversion.PurchaseOptions(contextKeys: ["mainOnboarding"])

Qonversion.shared().purchaseProduct(product, options: purchaseOptions) { (entitlements, error, isCancelled) in
  // handle result here
}
Objective-C
QONPurchaseOptions *purchaseOptions = [[QONPurchaseOptions alloc] initWithContextKeys:@[@"mainOnboarding"]];
[[Qonversion sharedInstance] purchaseProduct:product
                                     options:purchaseOptions
                                  completion:^(NSDictionary<NSString *,QONEntitlement *> * _Nonnull entitlements,
                                               NSError * _Nullable error,
                                               BOOL cancelled) {
  // handle result here
}];
Java
final QPurchaseOptions purchaseOptions = new QPurchaseOptions.Builder()
        .setContextKeys(Arrays.asList("mainOnboarding"))
        .build();
Qonversion.getSharedInstance().purchase(
    this,
    product,
    purchaseOptions,
    new QonversionEntitlementsCallback() {
        @Override
        public void onSuccess(@NotNull Map<String, QEntitlement> entitlements) {
            // handle result here
        }

        @Override
        public void onError(@NotNull QonversionError error) {
            // Handle error here
        }
    }
);
Kotlin
val purchaseOptions = QPurchaseOptions.Builder()
    .setContextKeys(listOf("mainOnboarding"))
    .build()
Qonversion.shared.purchase(
    this,
    product,
    purchaseOptions,
    callback = object : QonversionEntitlementsCallback {
        override fun onSuccess(entitlements: Map<String, QEntitlement>) {
            // handle result here
        }

        override fun onError(error: QonversionError) {
            // handle error here
        }
    }
)
Flutter
var purchaseOptions = QPurchaseOptionsBuilder()
    .setContextKeys(['mainOnboarding'])
    .build();
var entitlements = await Qonversion.getSharedInstance().purchaseProduct(
    product,
    purchaseOptions: purchaseOptions
);
React Native
const purchaseOptions = new PurchaseOptionsBuilder()
  .setContextKeys(['mainOnboarding'])
  .build();
const entitlements = await Qonversion.getSharedInstance().purchaseProduct(product, purchaseOptions);
Unity
var purchaseOptions = new PurchaseOptionsBuilder()
    .SetContextKeys(new List<string> {"mainOnboarding"})
    .Build();
Qonversion.GetSharedInstance().PurchaseProduct(product, purchaseOptions, (entitlements, error, isCancelled) =>
{
    // handle result here
});
Cordova
const purchaseOptions = new Qonversion.PurchaseOptionsBuilder()
  .setContextKeys(['mainOnboarding'])
  .build();
const entitlements = await Qonversion.getSharedInstance().purchaseProduct(product, purchaseOptions);
Capacitor
const purchaseOptions = new PurchaseOptionsBuilder()
  .setContextKeys(['mainOnboarding'])
  .build();
const entitlements = await Qonversion.getSharedInstance().purchaseProduct(product, purchaseOptions);