Integrate with Appsflyer for Advocate Programs

πŸ“˜

Tip:

We recommend testing your AppsFlyer integration on a mobile device, not a desktop, to ensure you see the most accurate and updated information.

Step 1: Activate Advocate as an integrated partner

Advocate is an AppsFlyer Integrated Partner (partner id: saasquatch_int). To begin, you must activate the partner integration from your dashboard.

  1. Open your AppsFlyer dashboard.
  2. Select Integrated Partners from the left sidebar menu.
  3. Search for the code SaaSquatch.
  4. Select the SaaSquatch partner and enable the Activate Partner toggle.
  5. Select Save Integration.

Step 2: Create a OneLink template and link

Follow AppsFlyer's documentation to create a:

After creating the OneLink link:

  1. Copy the Long or Short URL.
  2. Replace "CHANGEME" in the link with "saasquatch_int". This is the URL you will add to your Advocate program's integration settings.

For example, if your Long URL is:

https://my-one-link-for-saasquatch.onelink.me/JFlJ?pid=CHANGEME&c=MyCampaign

You will need to use the following URL in your Advocate program:

https://my-one-link-for-saasquatch.onelink.me/JFlJ?pid=saasquatch_int&c=MyCampaign

Step 3: Set up the AppsFlyer integration in impact.com

  1. In your impact.com account from the left navigation bar, select Β  [Menu] β†’ Settings.
  2. Under Advocate Settings, select Integrations.
  3. On the AppsFlyer integration card, select + [Expand].
  4. Select Enable Appsflyer.
  5. Add your modified Long or Short URL into the AppsFlyer Base Attribution Link field.
  6. Save the integration configuration.

You are now set up to use Appsflyer with your Advocate program.

Step 4: Update your Mobile App

To access the AppsFlyer deep linking data from within your mobile application, you will need to install the AppsFlyer SDK. The AppsFlyer documentation contains all the steps required to get their SDK setup on your application.

Once set up, you can retrieve the deep link data from AppsFlyer. This data contains information about the referral and can be used to attribute the referral and customize the signup experience for new users.

AppsFlyer may add other parameters depending on how your OneLink is configured. The most important parameter for your referral program is _saasquatch (or the equivalent deep_link_sub1, if you are using Unified Deep Linking). It contains the referral code and share link used for the referral, and is needed for attributing the referral. For more detail on data fields and behavior, refer to the AppsFlyer technical reference.

Here is an example of the referral program data that will be appended to the AppsFlyer OneLink:

{  
  "pid": "saasquatch_int",  
  "c": "saasquatch",  
  "af_web_dp": "<http://myReferralLandingPage.com">,  
  "deep_link_sub1": "eyJhcHAucmVmZXJyYWxzYWFzcXVhdGNoLmNvbSI6eyJ0ZXN0XzEyMzQ1NjdfQ09ERSI6eyJjb2RlcyI6eyJyZWZlcnJhbCI6IlJFRkVSUkFMQ09ERSJ9LCJjb2Rlc0V4cCI6eyJSRUZFUlJBTENPREUiOjE2Mjk1ODIxOTl9LCJsaW5rcyI6eyJyZWZlcnJhbCI6Imh0dHBzOi8vc3NxdC5jby9temFBMjIifSwibGlua3NFeHAiOnsiaHR0cHM6Ly9zc3F0LmNvL216YUEyMiI6MTYyOTU4MjE5OX19fX0=",  
  "deep_link_sub2": "invite",  
  "deep_link_sub3": "link",  
  "deep_link_sub4": "saasquatch",  
  "deep_link_sub5": "REFERRALCODE",  
  "deep_link_sub6": "UNKNOWN",  
  "deep_link_sub7": "UNKNOWN"  
}

Unified Deep Linking on iOS

Prior to implementing deep linking in your mobile application, be sure to follow the AppsFlyer IOS SDK initial setup documentation to initialize and implement the SDK in your application and read their IOS developer documentation for general information on setting up deep linking within your application.

Once you have followed the steps to set up unified deep linking and configured the Appsflyer integration in Advocate, referral information will be available in the deep_link_sub1 through deep_link_sub7 params. Below is a modified code example showing how to extract the _saasquatch cookie from the DeepLink data.

func application(\_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {  
  ...  
  AppsFlyerLib.shared().deepLinkDelegate = self  
  ...  
}

// For Swift version < 4.2 replace function signature with the commented out code  
// func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { // this line for Swift \< 4.2  
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {  
  AppsFlyerLib.shared().continue(userActivity, restorationHandler: nil)  
  return true  
}

// Open URI-scheme for iOS 9 and above  
func application(\_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {  
  AppsFlyerLib.shared().handleOpen(url, options: options)  
  return true  
}

extension AppDelegate: DeepLinkDelegate {  
    func didResolveDeepLink(\_ result: DeepLinkResult) {
    switch result.status {
    case .notFound:
        NSLog("[AFSDK] Deep link not found")
        return
    case .failure:
        print("Error %@", result.error!)
        return
    case .found:
        NSLog("[AFSDK] Deep link found")
    }

    guard let deepLinkObj:DeepLink = result.deepLink else {
        NSLog("[AFSDK] Could not extract deep link object")
        return
    }

    if deepLinkObj.clickEvent.keys.contains("deep_link_sub1") {
        let saasquatchCookie:String = deepLinkObj.clickEvent["deep_link_sub1"] as! String
        NSLog("[AFSDK] AppsFlyer: _saasquatch param: \(saasquatchCookie)")
    } else {
        NSLog("[AFSDK] Could not extract _saasquatch param")
    }

    let deepLinkStr:String = deepLinkObj.toString()
    NSLog("[AFSDK] DeepLink data is: \(deepLinkStr)")

    if( deepLinkObj.isDeferred == true) {
        NSLog("[AFSDK] This is a deferred deep link")
    }
    else {
        NSLog("[AFSDK] This is a direct deep link")
    }

    // ...
}
 }

Unified Deep Linking on Android

Prior to implementing deep linking in your mobile application, be sure to follow the AppsFlyer Android SDK initial setup documentation to initialize and implement the SDK in your application and read their Android developer documentation for general information on setting up deep linking within your application.

Once you have followed the steps to set up unified deep linking and configured the Appsflyer integration in Advocate, referral information will be available in the deep_link_sub1 through deep_link_sub7 params. Below is a modified code example showing how to extract the _saasquatch cookie from the DeepLink data.

appsflyer.subscribeForDeepLink(new DeepLinkListener(){  
            @Override  
            public void onDeepLinking(@NonNull DeepLinkResult deepLinkResult) {  
                DeepLinkResult.Status dlStatus = deepLinkResult.getStatus();  
                if (dlStatus == DeepLinkResult.Status.FOUND) {  
                    Log.d(LOG_TAG, "Deep link found");  
                } else if (dlStatus == DeepLinkResult.Status.NOT_FOUND) {  
                    Log.d(LOG_TAG, "Deep link not found");  
                    return;  
                } else {  
                    // dlStatus == DeepLinkResult.Status.ERROR  
                    DeepLinkResult.Error dlError = deepLinkResult.getError();  
                    Log.d(LOG_TAG, "There was an error getting Deep Link data: " + dlError.toString());  
                    return;  
                }  
                DeepLink deepLinkObj = deepLinkResult.getDeepLink();  
                try {  
                    Log.d(LOG_TAG, "The DeepLink data is: " + deepLinkObj.toString());  
                } catch (Exception e) {  
                    Log.d(LOG_TAG, "DeepLink data came back null");  
                    return;  
                }  
                // An example for using is_deferred  
                if (deepLinkObj.isDeferred()) {  
                    Log.d(LOG_TAG, "This is a deferred deep link");  
                } else {  
                    Log.d(LOG_TAG, "This is a direct deep link");  
                }
                            if (dlData.has("deep_link_sub1")){
                _saasquatch = deepLinkObj.getStringValue("deep_link_sub1");
                Log.d(LOG_TAG, "The SaaSquatch cookie is: " + _saasquatch);
            } else {
                Log.d(LOG_TAG, "deep_link_sub1/_saasquatch not found");
            }

            // ...
        }
    });