App Store Promoted Purchases

Promoting Your In-App Purchases on the App Store Page and Search Results

Promoted in-app purchases appear on your app page and can be displayed in search results. App Store promoted purchases are enabled by default. If a user starts in-app purchase from the App Store the purchase flow starts when a user opens your app.

iOS

Set delegate

If you need additional logic set QNPromoPurchasesDelegate.

Qonversion.setPromoPurchasesDelegate(self)
[Qonversion setPromoPurchasesDelegate:self];

Add the following function to handle promoted purchases

func shouldPurchasePromoProduct(withIdentifier productID: String, executionBlock: @escaping Qonversion.PromoPurchaseCompletionHandler) {
    // check AppStore productID value in case you want to enable promoted purchase only for specific products
    
    let completion: Qonversion.PurchaseCompletionHandler = {result, error, flag in
      // handle the purchased product or error
    }
    
    // call this block if you want to allow promoted purchase or just store block and call when needed
    // do nothing and do not call block if you don't want to allow purchase
    executionBlock(completion)
  }
- (void)shouldPurchasePromoProductWithIdentifier:(NSString *)productID executionBlock:(QNPromoPurchaseCompletionHandler)executionBlock {
  // check AppStore productID value in case you want to enable promoted purchase only for specific products
  
  QNPurchaseCompletionHandler completion = ^(NSDictionary<NSString *, QNPermission*> *result, NSError  *_Nullable error, BOOL cancelled) {
    // handle purchased product or error
  };
  
  // call this block if you want to allow promo purchase or just store block and call when needed
  // do nothing and do not call block if you don't want to allow purchase
  executionBlock(completion);
}

Flutter

Listen to promo purchase stream

Qonversion.promoPurchasesStream emits AppStore productID every time when a promoted purchase flow is triggered. Listen to the stream to handle promoted purchases.

StreamSubscription<String> _promoPurchasesStream;
_promoPurchasesStream = Qonversion.promoPurchasesStream.listen((productID) async {
  try {
    // check AppStore productID value in case you want to enable promoted purchase only for specific products
    // call `Qonversion.promoPurchase` if you want to allow promoted purchase or just store productID and call when needed
    // don't call `Qonversion.promoPurchase` if you don't want to allow purchase
    final permissions = await Qonversion.promoPurchase(productID);
  } catch (e) {
    print(e);
  }
});

Complete the purchase

Call Qonversion.promoPurchase when you want to initialize the purchase (for example, immediately after the onboarding screens) and pass the AppStore productID as the parameter. Alternatively, call this method immediately on app start.

try {
  final permissions = await Qonversion.promoPurchase(productID);
} catch (e) {
  print(e);
}

React Native

Listen to promo purchases events

Provide PromoPurchasesDelegate to get notified every time when a promoted purchase flow is triggered.

Qonversion.setPromoPurchasesDelegate({
    onPromoPurchaseReceived: async (productId, promoPurchaseExecutor) => {
        // check AppStore productId value in case you want to enable promoted purchase only for specific products
        // call `promoPurchaseExecutor` if you want to allow promoted purchase or just store productId and executor and call it when needed
        // don't call `promoPurchaseExecutor` if you don't want to allow purchase
    },
});

Complete the purchase

Call promoPurchaseExecutor provided to the delegate right in the delegate method or later when you want to initialize the purchase (for example, immediately after the onboarding screens) and pass the AppStore productId as the parameter.

try {
    const permissions = await promoPurchaseExecutor(productId);
    // handle permissions here
} catch (e) {
    // handle error here
}

Unity

Handle events

Qonversion.PromoPurchasesReceived sends the event each time a user initiates a promotional in-app purchase from the App Store. Declare a delegate to handle promo purchases. If you are not using thePromoPurchasesReceived event promo purchases will proceed automatically.

Qonversion.PromoPurchasesReceived += HandlePromoPurchases;

private void HandlePromoPurchases(string appStoreProductId, StartPromoPurchase startPromoPurchase)
{
    // check AppStore productID value in case you want to enable promoted purchase only for specific products
    // call `startPromoPurchase` if you want to allow promoted purchase or just store productID and call when needed
    // don't call `startPromoPurchase` if you don't want to allow purchase
}

Complete the purchase

Call startPromoPurchase when you want to initialize the purchase (for example, immediately after the onboarding screens).

startPromoPurchase((permissions, error) =>
{
    if (error == null)
    {
        if (permissions.TryGetValue("premium", out Permission premium) && premium.IsActive)
        {
            // Handle the active permission here
        }
    }
    else
    {
        // Handle the error  
        Debug.Log("Error" + error.ToString());
    }
});

Did this page help you?