SparkPost integration with AppsFlyer

At a glance: Learn how to embed AppsFlyer OneLink in SparkPost, an email delivery and analytics platform.


Email service providers (ESPs) are excellent sources of segmented user traffic. They wrap deep linking URLs with their own click recording domain. In some cases doing so breaks iOS Universal Links. To overcome this, SparkPost uses Universal Links on top of their click recording domain. They integrate with AppsFlyer and by using OneLink capabilities enable deep linking and click recording.

Setting up SparkPost

Configure SparkPost and the AppsFlyer SDK, to send emails containing OneLinks. 

For additional information on setting up SparkPost, reach out to SparkPost support. 


Mobile SDK versions:

  • iOS: V6.0.4 or later 
  • Android V6.0.0 or later 

Step 1: Setting in SparkPost

Create a dedicated click tracking domain and set a subdomain.

Set up sending domains and click-tracking domains, and enable HTTP engagement tracking.

Related reading getting started with SparkPost.

To set up domains and HTTP engagement tracking: 

  1. Open your SparkPost dashboard. 
  2. Go to Configuration > Sending Domains.
  3. Click Add a Domain, and follow the instructions in the user interface.
  4. Go to Configuration > Tracking Domains.
  5. Click Add a Domain, and follow the instructions in the user interface.
  6. To enable HTTPS engagement tracking: Follow SparkPost instructions about enabling SSL for the tracking domain.

Step 2: AASA hosting and custom link sub-path setup

For SparkPost to support iOS Universal Links, you need to upload an AASA file onto it.

When you set up OneLink with Universal Links, you already have an AASA associated with the OneLink. To get the AASA:

  1. In AppsFlyer, go to OneLink templates.
  2. Copy a OneLink that is configured with Universal Links.
  3. Add /.well-known/apple-app-site-association to the end of the OneLink URL.
    Example: <OneLinkSubdomain>
  4. Paste the OneLink in the browser address bar, then <enter>.
    The AASA file downloads to your computer.
  5. Follow SparkPost guide on how to configure Universal Links and create custom link sub-path.
  6. Host the AASA in your click recording domain server in SparkPost. Host the file in the path:
  7. After the click tracking domain is verified:
    1. Delete the Cname definition (example: example click ->
    2. Add a new Cname for your click tracking domain to your CDN (where the AASA file is located).
      Note: The first Cname is needed to verify your domain. It should then be deleted, and you need to Cname your subdomain to your CDN so you can have access to your AASA file. 

Once the AASA file is hosted, any modification or replacement of your OneLink configuration requires generating a new AASA file.

Step 3: Configure AppsFlyer SDK

Before configuring the AppsFlyer SDK, configure the app to support deep linking with OneLink.

Associate click recording domain in Xcode

  1. In Xcode, select your project.
  2. Select Capabilities.


  3. Turn on Associated Domains.
  4. Click + (plus), enter your click domain. For example,

Resolve deep links

To get campaign details, the SDK needs to resolve the OneLink behind the click domain. The details are returned in the onAppOpenAttribution method.
To resolve click domains:

  1. List the click domains in the SDK property resolveDeepLinkURLs.
    Make sure to set this property before SDK initialization.
  2. Define as part of resolving deeplink API.
    SparkPost owns this domain and its part of the redirection flow.


AppsFlyerLib.shared().resolveDeepLinkURLs = [“”,“”]

When a click on the Universal Link occurs, the app is invoked. AppsFlyer SDK resolves the deep link and extracts the underlying OneLink. Then, all deep link parameters are propagated into the onAppOpenAttribution API for deep link logic execution.
Learn more about resolving wrapped deep link URLs.

Send emails with OneLink through SparkPost

  1. Create a OneLink URL on the Link Management page (or manually). You must URL-encode parameter values.
  2. [Best practice] Use the following parameters:
    • pid (media source): Use a media source that signifies this usage such as Email.
    • c (campaign): Campaign name
    • 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 on an iOS device.
    • af_android_url: Where to redirect users that don’t have the app click the link on an Android device.
  3. Custom link sub-paths implementation: Insert the OneLink URL in the email created using the SparkPost Code Editor or Design Editor. For example:
    <a href=" data-msys-sublink="open-in-app">Link to your app!</a>
  4. If the email is part of a retargeting campaign, add the parameter is_retargeting=true.
    This indicates that the attribution link is from a retargeting campaign. Learn more about retargeting.
  5. SparkPost wraps the link with the defined click domain so that a click on the click domain redirects to the OneLink attribution link.


The URL parameters in the example that follows aren't encoded to enable ease of reading. 

Test your links

To test the integration:

  1. Set-up SparkPost.
  2. Create a OneLink URL.
  3. Insert the URL in an email.
  4. Send a test email to yourself. 

Expected result:

  • If you have the app installed, it should launch and you will be deep-linked into the defined app page.
  • A click reflects in:
    • The AppsFlyer dashboard, attributed to the media source and campaign.
    • SparkPost data.