User-invite attribution

Overview

Implement and attribute user-invite links and installs for when existing users refer others to your app.

Want to see a full example? Check out the recipe:

Implement user-invite attribution

To implement user-invite attribution:

  1. Set up Unified Deeplinking (UDL) if you haven't.

  2. Import the following dependencies if you haven't:

    import com.appsflyer.AppsFlyerLib;
    import com.appsflyer.CreateOneLinkHttpTask;
    import com.appsflyer.share.LinkGenerator;
    import com.appsflyer.share.ShareInviteHelper;
    
  3. Set a OneLink template using setAppInviteOneLink (The template ID is provided by the marketer):

    AppsFlyerLib.getInstance().setAppInviteOneLink("H5hv"); // set the OneLink template ID for user-invitation links
    

    📘

    Note

    Call setAppInviteOneLink before calling init and start.

  4. Create a LinkGenerator using ShareInviteHelper.generateInviteUrl().

    LinkGenerator linkGenerator = ShareInviteHelper.generateInviteUrl(getApplicationContext());
    

    📘

    Note

    generateInviteUrl creates a new LinkGenerator instance for you. You don't need to call new LinkGenerator....

  5. Depending on the user-flow you want to achieve, add the following parameters using addParameter():

    // Redirect referred user to a specific view
    linkGenerator.addParameter("deep_link_value", this.fruitName);
    // Pass referrer identifier to reward them
    linkGenerator.addParameter("deep_link_sub1", "user_referrer");
    
    • deep_link_value: The view the referred user should be deep-linked into.
    • deep_link_sub1: Referrer identifier. Can be used to reward the referrer.
  6. Set attribution parameters (will show up in the dashboard and raw-data).

    linkGenerator.setCampaign("share_invite");
    
  7. Create a CreateOneLinkHttpTask.ResponseListener to retrieve the user-invite link when it's ready:

    CreateOneLinkHttpTask.ResponseListener listener = new CreateOneLinkHttpTask.ResponseListener() {
                @Override
                public void onResponse(String s) {
                    // Copy the share invite link to clipboard and indicate it with a toast
                    // ...
                }
    
                @Override
                public void onResponseError(String s) {
                    Log.d(LOG_TAG, "onResponseError called");
                }
            };  
    }
    
  • onResponse is called when the user-invite is created successfully.
  • onResponseError is called when the user-invite failed to create.
  1. Pass listener to linkGenerator.generateLink():
    linkGenerator.generateLink(getApplicationContext(), listener);
    
  2. Log the invite using logEvent():
    // ...
    AppsFlyerLib.getInstance().logEvent(getApplicationContext(), AFInAppEventType.INVITE, null);
    

Did this page help you?