Create Universal Links for iOS
Learning Objectives
After completing this unit, you’ll be able to:
- Implement an iOS Universal Link.
- Test your iOS Universal Links.
- Exclude links from your iOS Universal Link implementation.
Create Your iOS Universal Links
Marketing Cloud Engagement implements iOS Universal Links as a tenant-wide feature, but it also requires enablement within your mobile app. Fortunately, Pia can work with NTO’s app developers to get all of these changes accomplished with very little effort. Let’s take a look as she starts with app development, then moves into configuring her Marketing Cloud Engagement tenant.
In this module, we assume you are a Marketing Cloud Engagement admin with the proper permissions and access to create deep links. If you can’t access these features, that’s OK. Read along to learn how Pia would take the steps in a production org. Don't try to follow these steps in your Trailhead Playground. Marketing Cloud Engagement isn't available in the Trailhead Playground.
Complete the Links in Your Mobile App
Remember when we mentioned you’d need an SAP and SSL certificate for the click domain? This step is where that information becomes crucial. Pia talks to the NTO app developers about including the branded click domain link entry in the com.apple.developer.associated-domains entitlement. The entry looks something like this example.
"applinks:click.example.com"
The developers also have to modify the webpageURL property on the NSUserActivity object (provided by iOS) to receive URLs like the following example and determine if they come from the correct click domain.
https://click.example.com/?qs=hxdwbvpwueDMUFuWaNEhguEVdMLWCPTsutky0fd
The developers add a GET request to unwrap the URL and send the customer to the correct location. Because NTO uses Einstein Content Selection to provide individualized product selections to their subscribers, the developers must also include a GET request for possible Einstein URLs as well.
https://ecs.us.sfmc-einstein.com/einstein/api/block/44644947...
After unwrapping the URL and retrieving the destination, the developers write code to help them resolve the final URL and where they need to take the customer. They draw out code to help resolve all the links and it looks something like this.
public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { // Example: Double wrapped url if let url = userActivity.webpageURL { if url.absoluteString.contains("sfmc-einstein") { Networking.getUnwrapped(url) { result in switch result { case .success(let singleUnwrappedURL): // first unwrapped link; will need to be unwrapped again Networking.getUnwrapped(singleUnwrappedURL) { result in switch result { case .success(let doubleUnwrappedURL): // Final unwrapped link to be parsed by app parseAndRedirect(with: doubleUnwrappedURL) case .failure: print("Failed to get 2nd unwrapped link") } } case .failure: print("Failed to get 1st unwrapped link") } } } } return true }
The code for this process directs the message to the correct location, as illustrated in the following figure.
Complete the Settings in Email Studio
Pia then logs into Marketing Cloud Engagement and configures the account for use with iOS Universal Links.
- In Marketing Cloud Engagement, Pia navigates to Email Studio and clicks the Admin tab.
- She clicks Send Management and selects Deep Linking.
- She clicks Create.
- Pia enters the AppID value (the application's alphanumeric teamID) followed by the bundleID.
- She leaves the Type dropdown on iOS.
- She forces a mobile web experience for Marketing Cloud Engagement profile and subscription centers by selecting Exclude Profile and Unsub Center.
- She saves the entry.
This process saves and hosts an apple-app-site-association file on your subdomain, like: https://click.example.com/.well-known/apple-app-site-association
. The actual file looks something like this.
{ "applinks": { "apps": [], "details": [ { "appID": "ABC123EFG.com.staging.app", "paths": [ "NOT /subscription_center.aspx*", "NOT /profile_center.aspx*", "NOT /unsub_center.aspx*", "NOT /u/*", "/*" ] }, { "appID": "HJK456LMN.com.production.app", "paths": [ "NOT /subscription_center.aspx*", "NOT /profile_center.aspx*", "NOT /unsub_center.aspx*", "NOT /u/*", "/*" ] } ] } }
From here, Pia can test the implementation of iOS Universal Links. She adds the domain to the iOS application entitlement and gets to work by sending email messages using iOS Universal Links to development versions of the NTO app.
Now, here’s an important note. iOS Universal Links forces your Marketing Cloud Engagement account to think all links open in the mobile app. To make sure that she doesn’t direct specific links to the mobile app, Pia alerts her team to include a string in non-app links for their email messages.
- Pia asks the team to open the HTML version of the email message containing the link.
- Her team adds
mc-deep-link="false"
to the <a> tag of the link, like<a href="https://www.example.com" mc-deep-link="false">Your Link</a>
. - Finally, they save the email message.
Pia has the iOS side of deep linking covered with this feature. In the next unit, she tackles Android implementation.