SparkPost integration with AppsFlyer

At a glance: SparkPost, an email delivery and analytics platform, embeds AppsFlyer OneLink within emails. Email recipients, clicking on the link are deep-linked into an app. 

sparkpost-logo_en-us.png

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. 

Prerequisite

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.
Example: click.example.com.

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.
  4. Follow the instructions in the user interface.
  5. Go to Configuration > Tracking Domains.
  6. Click Create Tracking Domain.
  7. Follow the instructions in the user interface.
  8. 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>.onelink.me/.well-known/apple-app-site-association.
  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: click.example.com/.well-known/apple-app-site-association.
  7. After the click tracking domain is verified:
    1. Delete the cname definition (example: example click -> spgo.io).
    2. Cname your click tracking domain to your CDN (where the AASA file is located).
 Important!

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.
    configure-xcode-deeplinking-domain_en-us.png
  3. Turn on Associated Domains.
  4. Click + (plus), enter your click domain. For example, applinks:click.example.com.

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 “spgo.io” as part of resolving deeplink API.
    SparkPost owns this domain and it’s part of the redirection flow.

 Example

AppsFlyerLib.shared().resolveDeepLinkURLs = [“click.example.com”,“spgo.io”]

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 in 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 in an iOS device.
    • af_android_url: Where to redirect users that don’t have the app click the link in an Android device.
  3. Insert the OneLink URL in the email created using the SparkPost Code Editor or Design Editor. Example:
    <a href="links.example.com data-msys-sublink="appsflyer">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.

 Example

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

https://example.onelink.me/abcd?pid=Email&c=Spring_Newsletter&is_retargeting=true& 
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

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.
Was this article helpful?