Skip to main content

How do I send events with deeplinks?

This article provides examples of how to use deeplinks to send events. These examples show how to implement deeplinks both from within your app or by linking to your app from a partner app.

Implementing the below examples in your code enables your Swrve users to send events via deeplinks from in-app messages of the form: swrve://?event=

[SwrveSDK messaging].customButtonCallback = ^(NSString* action){
NSURL *url = [NSURL URLWithString:action];
double delayInSeconds = 0.25;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if ([url.scheme isEqualToString:@"swrve"]){
NSArray *pairs = [url.query componentsSeparatedByString:@"&"];
for(NSString *pair in pairs){
NSString key=[[pair componentsSeparatedByString:@"="] objectAtIndex:0];
NSString value=[[pair componentsSeparatedByString:@"="] objectAtIndex:1];
if([key isEqualToString:@"event"]){
[SwrveSDK event:value];
}
}
[SwrveSDK sendQueuedEvents];
}
else{
[[UIApplication sharedApplication] openURL:url];
}
});
}

By allowing your Swrve users to send custom events via deeplink, you can track which app users engaged with campaigns. This allows targeting of these users or linking of in-app message campaigns. It is also possible to expand this code for different key-value pairs to allow deeplinks to send user properties, purchases, and so forth.


Use case

The key use case for sending events via deeplink is enabling your Swrve users to link in-app message campaigns. In the following example, you can create a tutorial flow of messages in Swrve without any changes to your code—once your app is set up to send events via deeplink.

The first message can be triggered by any event, such as visiting the home screen, once the action is a deeplink which sends a custom event:

In-app action deeplink

Subsequent messages can then be triggered by the event fired by the previous message:

event trigger deeplink