Purchasely supports the use of Deeplinks to trigger different actions to improve conversion, retention and upsell. You can send a Push or an email with that deeplink and Purchasely will open the requested presentation or page for you.
Here are the actions Purchasely supports:
Display a product page (paywall)
Display the user subscriptions
Display the cancellation survey
Update credit card (Deeplink to App Store)
Integration
To integrate these automations you need 2 things:
Pass the deeplink to Purchasley when it is received by the application
Allow Purchasely to display content over your interface
Pass the Deeplink to Purchasely
The first thing you need to do is to pass the deeplink URL to Purchasely when your app receives it:
// ---------------------------------------------------// If you are **NOT** using SceneDelegate// ---------------------------------------------------// AppDelegate.swiftimportPurchaselyfuncapplication(_application: UIApplication, openurl: URL, sourceApplication: String?, annotation: Any) ->Bool {// You can chain calls to multiple handler using a ORreturn Purchasely.handle(deeplink: url)}// ---------------------------------------------------// If you are using SceneDelegate// ---------------------------------------------------// SceneDelegate.swiftimportPurchaselyfunc scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// …iflet url = connectionOptions.urlContexts.first?.url {_= Purchasely.handle(deeplink: url) }}funcscene(_scene: UIScene, openURLContextsURLContexts: Set<UIOpenURLContext>) {iflet url = URLContexts.first?.url {_= Purchasely.handle(deeplink: url) }}
// ---------------------------------------------------
// If you are **NOT** using SceneDelegate
// ---------------------------------------------------
// AppDelegate.m
#import <Purchasely/Purchasely-Swift.h>
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// You can chain calls to multiple handler using a OR
return [Purchasely handleWithDeeplink:url];
}
// ---------------------------------------------------
// If you are using SceneDelegate
// ---------------------------------------------------
// SceneDelegate.m
#import <Purchasely/Purchasely-Swift.h>
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// …
NSURL *url = connectionOptions.URLContexts.allObjects.firstObject.URL;
if (url != nil) {
[Purchasely handleWithDeeplink:url];
}
}
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
NSURL *url = URLContexts.allObjects.firstObject.URL;
if (url != nil) {
[Purchasely handleWithDeeplink:url];
}
}
classMyActivity : FragmentActivity() {overridefunonCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)//retrieve intent data to get deeplink that opened your activityvaldata= intent.dataif(data!=null) {//Purchasely sdk will return true if it handles the deeplinkval isHandledByPurchasely = Purchasely.handle(data) } } }
publicclassMyActivityextendsFragmentActivity { @OverrideprotectedvoidonCreate(@NullableBundle savedInstanceState) { super.onCreate(savedInstanceState);//retrieve intent data to get deeplink that opened your activityUri data =getIntent().getData();if(data !=null) {//Purchasely sdk will return true if it handles the deeplinkboolean isHandledByPurchasely =Purchasely.handle(data); } }}
Purchasely.handle('app://ply/presentations/').then((value) =>console.log('Deeplink handled by Purchasely ? '+ value));
// If you grab the deeplink inside your Cordova code you can callPurchasely.handle("app://ply/presentations/", (handled) => {console.log("Was deeplink handled by Purchasely? "+ handled);});
Purchasely.handle('app://ply/presentations/') .then((value) =>print('Deeplink handled by Purchasely ? $value'));
Allow display
Your app might have a launch routine that requires to be fulfilled before another screen can be displayed. It can be splash screen, on boarding, login …
The display of Purchasely deeplinks is deferred until you authorize it. Once your app is ready, notify Purchasely.
Purchasely.isReadyToPurchase(true)
[Purchasely isReadyToPurchase: YES];
Purchasely.isReadyToPurchase =true
Purchasely.setReadyToPurchase(true);
Purchasely.isReadyToPurchase(true);
Purchasely.isReadyToPurchase(true);
Purchasely.isReadyToPurchase(true);
Get presentation result
When a deeplink is called, as you don't instanciate the paywall yourself, no closure will be called to tell you what happened.
You can retrieve the result of the user action in a paywall opened with a deeplink by setting a DefaultPresentationResultHandler.
[Purchasely setDefaultPresentationResultHandler:^(enum PLYProductViewControllerResult result, PLYPlan * _Nullable plan) {
switch (result) {
case PLYProductViewControllerResultPurchased:
break;
case PLYProductViewControllerResultRestored:
break;
case PLYProductViewControllerResultCancelled:
break;
default:
break;
}
}];
Purchasely.setDefaultPresentationResultHandler { result, plan ->/* You can set a callback to know when your user purchased a product */when(result) { PLYProductViewResult.PURCHASED -> Log.d("Purchasely", "Purchased $plan") PLYProductViewResult.CANCELLED -> Log.d("Purchasely", "Cancelled purchase of $plan") PLYProductViewResult.RESTORED -> Log.d("Purchasely", "Restored $plan") }}
Purchasely.setDefaultPresentationResultHandler(newProductViewResultListener() { @OverridepublicvoidonResult(@NotNullPLYProductViewResult result, @org.jetbrains.annotations.NullablePLYPlan plan) {/* You can set a callback to know when your user purchased a product */switch (result) {case PURCHASED:break;case CANCELLED:break;case RESTORED:break; } }});
Purchasely.setDefaultPresentationResultCallback((result) => {console.log('Presentation View Result : '+result.result);if (result.plan !=null) {console.log('Plan Vendor ID : '+result.plan.vendorId);console.log('Plan Name : '+result.plan.name); }});
Purchasely.setDefaultPresentationResultCallback( (PresentPresentationResult value) {print('Presentation Result : '+ value.result.toString());if (value.plan !=null) {//User bought a plan }});
The callback PLYProductViewControllerResult(iOS) / ProductViewResultListener (Android) is optional, you can set to null if you do not need it. You can override it when you display a presentation directly.
Supported deeplinks
Product
You can open a product presentation directly to the user with the default presentation or a specific one used for a specific purpose / promotion.