SendGrid integration with AppsFlyer

At a glance: SendGrid, an email delivery and analytics platform, embeds AppsFlyer OneLink within emails. When email recipients click on the link, they are deep-linked into your app.



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 oftentimes 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.


  • AppsFlyer iOS SDK version 4.9.0+

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 (for example,

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:

/hc/article_attachments/360002714678/SendGrid_step_1.png For more information, refer to SendGrid documentation:

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

  1. Obtain an AASA. There are two ways to do this:
    • Ask your developer to review Apple guide on universal links. The guide explains how to create the AASA.
    • Alternatively, if you set up OneLink with Universal Links, you might already have an AASA associated with the OneLink. To obtain the AASA, go to OneLink configuration, find a OneLink that is configured with Universal Links, and obtain the OneLink ID. The OneLink ID appears on the first column of the table that lists all existing OneLink configurations. Once you have the ID, paste it to the following URL in the browser address bar, and click enter: <OneLinkSubdomain> When you do so, the AASA file is downloaded to your computer. You can open it using any simple text editor.
  2. Host the AASA in your click recording domain server. The file should be hosted in the path:
    Learn more about SendGrid universal links.


Once the AASA file is hosted, any change of your OneLink configuration (either modification or replacement) requires generating a 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 need to set up your app to deep-link and resolve that Universal Link.

  1. Associate the click recording domain in Xcode:

  2. 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.
    [[AppsFlyerLib shared] resolveDeepLinkURLs = @[@"",@""];
  3. 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

  1. Create a OneLink URL in the Link Management page (or manually)
  2. When creating the OneLink URL make sure to URL encode all parameter values
  3. 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 a desktop computer
    • 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
  4. 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:
    <a href="" universal="true">Link to your app!</a>
    Note that SendGrid adds the `/uni/` parameter when "universal=true" is included.
  5. If the email is retargeting existing users, add to OneLink the parameter is_retargeting=true.
    This converts the attribution link from a user acquisition type URL to a retargeting URL. Learn more.
  6. 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:

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