Handle Automation Result
Testing Automation
Make sure
debug mode
is enabled when testing Automations.
CallQonversion.setDebugMode()
before callingQonversion.launch()
.
Do not forget to remove this line for the production build.
Automations Delegate
To handle Automations result call setDelegate
and implement the following functions.
Set Automations delegate
You can skip this step if you don't need to handle the Qonversion Automations result.
Qonversion.Automations.setDelegate(self)
[QONAutomations setDelegate:self];
Automations.setDelegate(object : AutomationsDelegate {
// Override functions here
})
Automations.setDelegate(new AutomationsDelegate() {
// Override functions here
});
// This method is not relevant for Flutter
Automations.setDelegate({
// Override functions here
});
Automations.SetDelegate(delegate);
Implement Qonversion.AutomationsDelegate
functions
Qonversion.AutomationsDelegate
functions1. Controller for navigation
This function returns the controller for the navigation in iOS and context for screen intent in Android. This is an optional function.
func controllerForNavigation() -> UIViewController {
// return controller for automations flow presentation
}
- (UIViewController * _Nonnull)controllerForNavigation {
// return controller for automations flow presentation
}
override fun contextForScreenIntent(): Context {
// Provide the context for screen intent
}
@NotNull
@Override
public Context contextForScreenIntent() {
// Provide the context for screen intent
}
// This method is not relevant for Flutter
// This method is not relevant for React Native
// This method is not relevant for Unity
2. Automations states
All of these functions are optional.
First, you can handle the function that notifies you that Automations' screen is shown. You can do additional logic or just track an event here:
func automationsDidShowScreen(_ screenID: String) {
// do some logic or track event
}
- (void)automationsDidShowScreen:(NSString * _Nonnull)screenID {
// do some logic or track event
}
override fun automationsDidShowScreen(screenId: String) {
// do some logic or track event
}
@Override
public void automationsDidShowScreen(@NotNull String screenId) {
// do some logic or track event
}
StreamSubscription<String> _shownScreensStream;
_shownScreensStream = Automations.shownScreensStream.listen((event) {
// do any logic you need
});
automationsDidShowScreen(screen) {
// do some logic or track event
}
public override void OnAutomationsScreenShown(string screenId)
{
// do some logic or track event
}
Then, you can handle Automations start, fail, or finish executing an action with the following functions:
Same as in the previous step, you can do additional logic or just track events here:
2.1. Start:
func automationsDidStartExecuting(actionResult: Qonversion.ActionResult) {
// do some logic or track event
}
- (void)automationsDidStartExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
// do some logic or track event
}
override fun automationsDidStartExecuting(actionResult: QActionResult) {
// Do some logic or track event
}
@Override
public void automationsDidStartExecuting(@NotNull QActionResult actionResult) {
// Ddo some logic or track event
}
StreamSubscription<ActionResult> _startedActionsStream;
_startedActionsStream = Automations.startedActionsStream.listen((event) {
// do any logic you need or track event
});
automationsDidStartExecuting(actionResult) {
// do some logic or track event
}
public override void OnAutomationsActionStarted(ActionResult actionResult)
{
// do some logic or track event
}
2.2. Fail
func automationsDidFailExecuting(actionResult: Qonversion.ActionResult) {
// do some logic or track event
}
- (void)automationsDidFailExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
// do some logic or track event
}
override fun automationsDidFailExecuting(actionResult: QActionResult) {
// Do some logic or track event
}
@Override
public void automationsDidFailExecuting(@NotNull QActionResult actionResult) {
// Do some logic or track event
}
StreamSubscription<ActionResult> _failedActionsStream;
_failedActionsStream = Automations.failedActionsStream.listen((event) {
// do any logic you need or track event
});
automationsDidFailExecuting(actionResult) {
// do some logic or track event
}
public override void OnAutomationsActionFailed(ActionResult actionResult)
{
// do some logic or track event
}
2.3. Finish
You can use this function to get information if a user makes a purchase within the Automations flow. In this case, you need to check user's permissions ('checkPermissions') to unlock access to your app's premium content.
func automationsDidFinishExecuting(actionResult: Qonversion.ActionResult) {
if actionResult.type == .purchase {
Qonversion.checkPermissions { (resul, error) in
// handle new permissions here
}
}
}
- (void)automationsDidFinishExecutingActionResult:(QONActionResult * _Nonnull)actionResult {
if (actionResult.type == QONActionResultTypePurchase) {
[Qonversion checkPermissions:^(NSDictionary<NSString *,QNPermission *> * _Nonnull result, NSError * _Nullable error) {
// handle new permissions here
}];
}
}
override fun automationsDidFinishExecuting(actionResult: QActionResult) {
if (actionResult.type == QActionResultType.Purchase) {
Qonversion.checkPermissions(object :QonversionPermissionsCallback{
// Handle new permissions here
})
}
}
@Override
public void automationsDidFinishExecuting(@NotNull QActionResult actionResult) {
if (actionResult.getType() == QActionResultType.Purchase) {
Qonversion.checkPermissions(new QonversionPermissionsCallback() {
// Handle new permissions here
});
}
StreamSubscription<ActionResult> _finishedActionsStream;
_finishedActionsStream = Automations.finishedActionsStream.listen((event) {
if (event.type == ActionResultType.purchase) {
// do any logic you need
}
});
automationsDidFinishExecuting(actionResult) {
if (actionResult.type === ActionResultType.PURCHASE) {
Qonversion.checkPermissions().then(permissions => {
// Handle new permissions here
});
}
}
public override void OnAutomationsActionFinished(ActionResult actionResult)
{
// do some logic or track event
}
2.4. Automations finished
This function is called when Automations flow is finished and the Automations screen is closed.
func automationsFinished() {
// do any logic you needed
}
- (void)automationsFinished {
// do any logic you needed
}
override fun automationsFinished() {
// Do any logic you needed
}
@Override
public void automationsFinished() {
// Do any logic you needed
}
StreamSubscription<Null> _finishedAutomationsStream;
_finishedAutomationsStream =
Automations.finishedAutomationsStream.listen((event) {
// do any logic you need or track event
});
automationsFinished() {
// do some logic or track event
}
public override void OnAutomationsFinished()
{
// do some logic or track event
}
3. Automation events
This function allows identifying the event type that triggered the Automation.
Override this method and return false if you want to handle the event by yourself. Otherwise, Qonversion handles the event and shows the Automation screen (if it's configured). This is an optional function.
In case you want to handle push results on your side and show different screens to users that received push notifications triggered by different events, you need to handle the Automation event, check the event type, and show the screen required.
func shouldHandle(_ event: QONAutomationsEvent, payload: [String : Any]) -> Bool {
// check event.type here
// return false if you want to handle event yourself
// for example
if event.type == .subscriptionCanceled {
return false
} else {
return true
}
}
- (BOOL)shouldHandleEvent:(QONAutomationsEvent *)event payload:(NSDictionary<NSString *,id> *)payload {
// check event.type here
// return false if you want to handle event yourself
// for example
if (event.type == QONAutomationsEventTypeSubscriptionCanceled) {
return false;
} else {
return true;
}
}
override fun shouldHandleEvent(
event: AutomationsEvent,
payload: MutableMap<String, String>
): Boolean {
// check event.type here
// return false if you want to handle the event on your side
// for example
if (event.type == AutomationsEventType.SubscriptionCanceled) {
return false
} else {
return true
}
}
@Override
public Boolean shouldHandleEvent(@NotNull AutomationsEvent event, @NotNull Map<String, String> payload) {
// check event.type here
// return false if you want to handle the event on your side
// for example
if (event.getType() == AutomationsEventType.SubscriptionCanceled) {
return false;
} else {
return true;
}
}
// Will be available soon
// Will be available soon
// Will be available soon
Updated 2 months ago