Adding Deep Linking Support
When a user clicks a deep link on a device that has the app installed, the app opens and shows a specific product or experience.
Singular tracking links can include deep linking functionality as well as deferred deep linking (see our Deep Linking FAQ and the Singular Links FAQ for more information).
The Singular SDK Config, implemented in the previous step, references a callback function ("handleDeeplink"). The "handleDeeplink" function is required to enable deep link and deferred deep link support through the Singular SDK.
Prerequisites for Implementing Deep Links
Make sure you have completed the following steps:
- Followed the instructions in Singular Links Prerequisites.
- In Xcode, added a Singular Custom Subdomain to Signing & Capabilities > Associated Domains.
- Added the app scheme to your URL Types at Info > URL Types.
- Added your Apple Developer Team ID and Scheme in the Apps page in the Singular platform.
Notes:
- If the app is already configured to use iOS Universal Links, the Universal Link domain already exists in Associated Domains and can remain. This domain should be added to the Supported Domains config option, as noted in the next section.
- You must also include the Singular custom link domain, so that Singular can track attributions from marketing campaigns and handle deep links from these campaigns.
Creating the Callback Method for the Handler
The code example below creates a callback method called handleDeeplink (this method is referenced in the Config code sample above).
The block signature is void(^)(SingularLinkParams*). The SingularLinkParams contains the deep link destination, passthrough parameters, and whether the link is deferred or not.
func handleDeeplink(params: SingularLinkParams?) {
// Get Deeplink data from Singular Link
let deeplink = params?.getDeepLink()
let passthrough = params?.getPassthrough()
let isDeferredDeeplink = params?.isDeferred()
let urlParams = params?.getUrlParameters()
// Add deep link handling code here
//...
}
- (void)handleDeeplink:(SingularLinkParams*)params{
// Get Deeplink data from Singular Link
NSString *deeplink = [params getDeepLink];
NSString *passthrough = [params getPassthrough];
BOOL isDeferredDeeplink = [params isDeferred];
NSDictionary *urlParams = [params getUrlParameters];
// Add deep link handling code here
//...
}
Other Link Options
The Singular SDK also supports Universal Links that aren't served by Singular. This is required for measuring attribution for partners who support deep linking, such as for Google Ads and Facebook.
For Singular iOS SDK versions 12.0.3 and above, non-Singular Universal Links are supported by default.
To support third-party deep links in older versions of the SDK:
- In older versions of the Singular iOS SDK, you need to add all associated domains (excluding sng.link) to the supportedDomains configuration option (in the Config object) every time the Singular SDK is initialized. This allows for the third-party deep link behavior but does not allow for attribution to the deep link. For attribution, you still have to use Singular tracking links.
- supportedDomains functionality assumes you have configured your app for Universal Links and currently host your own AASA file on your domain.
func getConfig() -> SingularConfig? {
// Singular Config Options
guard let config = SingularConfig(apiKey: Constants.APIKEY,
andSecret: Constants.SECRET) else {
return nil
}
//...
config.supportedDomains = ["subdomain.mywebsite.com",
"anothersubdomain.myotherwebsite.com"]
//...
return config
}
- (SingularConfig *)getConfig {
// Singular Config Options
SingularConfig* config = [[SingularConfig alloc] initWithApiKey:APIKEY
andSecret:SECRET];
//...
config.supportedDomains = @[@"subdomain.mywebsite.com",
"anothersubdomain.myotherwebsite.com"];
//...
return config;
}
The Singular SDK supports Universal Links served by ESPs (Email Service Providers).
The ESP domain must be HTTPS-enabled. Apple requires that iOS apps pull apple-app-site-association files from an HTTPS-enabled endpoint without redirects. Check with your ESP how they host this file for your app, as it may require DNS configuration on your site's DNS. Typically, the ESP will provide the steps needed to enable HTTPS.
To support an ESP domain, add the custom tracking domain to the espDomains configuration option (in the config object) every time the Singular SDK is initialized.
func getConfig() -> SingularConfig? {
// Singular Config Options
guard let config = SingularConfig(apiKey: Constants.APIKEY,
andSecret: Constants.SECRET) else {
return nil
}
//...
config.espDomains = ["links.mywebsite.com"]
//...
return config
}
- (SingularConfig *)getConfig {
// Singular Config Options
SingularConfig* config = [[SingularConfig alloc] initWithApiKey:APIKEY
andSecret:SECRET];
//...
config.espDomains = @[@"links.mywebsite.com"];
//...
return config;
}