ESPs (Email Service Providers) can be excellent sources for segmented user traffic.
One of the problems with ESPs is recording clicks while still persevering deep linking functionality. ESPs wrap the deep linking URL with their own ESP's click recording domain. This procedure often times breaks the iOS Universal Links process.
However, with ESPs that support Universal Links on top of their click recording domain, deep linking and click recording can still be performed.
This article explains the flow for integrating OneLink-based attribution links into your Sendgrid based email system in order to seamlessly deep link from emails. The integration utilizes Sendgrid’s support for Universal Links on top of the branded click recording domain.
- AppsFlyer iOS SDK version 4.9.0
- AppsFlyer Android SDK version 4.9.0
SendGrid doesn’t support Android App Links. However, URI Scheme deep linking is still supported. No special actions are required to support deep linking in Android apps from SendGrid.
Setting Up SendGrid
Step 1 - Set up Link Branding in SendGrid
In order to use Universal Links with SendGrid, you need to create a dedicated click recording domain and set a subdomain (e.g. click.example.com).
This can be done by purchasing a designated domain, or using your own domain.
Subdomain configuration is accessible in SendGrid via “Advance Settings”, by checking the “Use a custom link subdomain” and adding your subdomain:
Step 2 - Set up SSL for click recording
After you set click recording domain and Link Branding, follow SendGrid's instructions on how to enable SSL click and open recording for an authenticated domain.
Step 3 - Apple App Site Association File (AASA) Hosting
- Contact your AppsFlyer CSM to generate an AASA file for SendGrid Universal Link usage. Provide the click recording URL (e.g. click.example.com), and the OneLink ID that you use for creating OneLink Attribution Links within your emails.
- Host the AASA in your click recording domain server. The file should be hosted in the path: click.example.com/apple-app-site-association.
Once the AASA file is hosted, any change of your OneLink configuration (either modification or replacement) requires generating new AASA file.
Step 4 - Configuring your AppsFlyer SDK
If you haven’t already done so, make sure you have configured your app to support deep linking with OneLink.
After configuring your click recording domain to support Universal Links as described previously, you will need to set up your app to deep link and resolve that Universal Link.
- Associate the click recording domain in Xcode:
- Provide the click recording domain to the SDK API
setResolveDeepLinkURLs. This API needs to be called before SDK initialization. For more information please refer to SDK documentation here.
[[AppsFlyerTracker sharedTracker] setResolveDeepLinkURLs:@[@"click.example.com"]];
- When the app is invoked due to a click on the Universal Link, the AppsFlyer SDK resolves the deep link and extracts the underlying OneLink. All deep link parameters are then propagated into the onAppOpenAttribution API for deep link logic execution.
Step 5 - Sending Your First Email
- Create a OneLink URL in the Link Management page (or manually)
- When creating the OneLink URL make sure to URL encode all parameter values
- The following parameters are highly recommended to use:
- pid (media source) - Use a media source that signifies this usage such as Email.
- c (campaign) - The name of the campaign you want to measure
- af_dp - The deep link URI scheme you want to deep link your users into
- af_web_dp - Where to redirect users clicking the link on desktop
- af_ios_url - Where to redirect users that don’t have the app clicking the link in an iOS device
- af_android_url - Where to redirect users that don’t have the app click the link in an Android device
- Place the OneLink URL in the email you are creating in SendGrid's Code Editor or Design Editor. To enable Universal Links for it, include the attribute "universal=true" in the HTML link tag of your email template. Example:
Note that SendGrid adds the `/uni/` parameter when "universal=true" is included.
<a href="links.example.com" universal="true">Link to your app!</a>
- At this stage, SendGrid wraps the above link with the click recording domain that you set in the previous steps. Any click on the click recording domain will redirect to the OneLink attribution link.
URL parameters are not URL encoded in this example, just for the sake of readability:
https://example.onelink.me/ABcd?pid=Email&c=Spring_Newsletter& af_dp=testapp://path/to/content&af_web_dp=https://www.example.com/path/to/content& af_ios_url=https://www.example.com/path/to/content&af_android_url=https://www.example.com/path/to/content
Step 6 - Testing Your Links
After following all the required steps mentioned above, creating the appropriate OneLink URL, and placing it in an email, send yourself a test email.
What should you expect?
If you have the app installed, the app should be invoked. If the relevant AppsFlyer SDK deep linking APIs are implemented you should be deep linked into the relevant content.
In addition, a click should appear in both the AppsFlyer dashboard, attributed to the provided media source and campaign, and also in SendGrid's data