Android User Invite

Implement user invites

Before you begin: Sync with the marketer to find out the exact use cases they want for the links and to get a list of the parameters they want to be implemented.

To implement user invite attribution, complete the following steps:

  1. Set up invite link generation to generate invite links.
  2. Optional Log the invite link creation.
  3. Set up Unified Deep Linking (UDL)
  4. Optional Retrieve referrer data from user invite links.
  5. Optional Set up referrer rewards.

The following code is based on the marketer example.

Set up invite link generation

To enable users to invite their friends to your app, you need a way to generate user invite links. This is done using LinkGenerator.
To set up user invite link generation:

  1. Make sure to import the following dependencies:

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

    AppsFlyerLib.getInstance().setAppInviteOneLink("H5hv"); // set the OneLink template ID the user invite links will be based on



    • Make sure to call setAppInviteOneLink() before calling start.
    • The OneLink template must be related to the app.
  3. Create a LinkGenerator using ShareInviteHelper.generateInviteUrl().

    LinkGenerator linkGenerator = ShareInviteHelper.generateInviteUrl(getApplicationContext());
  4. Depending on the user flow you want to achieve, add the following parameters using linkGenerator.addParameter():

    linkGenerator.addParameter("deep_link_value", <TARGET_VIEW>);
    linkGenerator.addParameter("deep_link_sub1", <PROMO_CODE>);
    linkGenerator.addParameter("deep_link_sub2", <REFERRER_ID>);
    // Optional; makes the referrer ID available in the installs raw-data report
    linkGenerator.addParameter("af_sub1", <REFERRER_ID>);
    • deep_link_value: The app experience the referred user should be deep linked into.
    • deep_link_sub1: Promo code received by the invitee.
    • deep_link_sub2: Referrer identifier. Can be used to reward the referrer.
    • Note: If you have SDK V6.5.2 or lower, you need to encode any parameter values with special characters.
  5. Set attribution parameters. (These will display in AppsFlyer dashboards and raw data reports).

  6. Optional Set a branded domain for the generated link:

  7. Create a LinkGenerator.ResponseListener to retrieve the user invite link when it's available:

    LinkGenerator.ResponseListener listener = new LinkGenerator.ResponseListener() {
                public void onResponse(String s) {
                    Log.d(LOG_TAG, "Share invite link: " + s);
                    // ...
                public void onResponseError(String s) {
                    Log.d(LOG_TAG, "onResponseError called");



    Since SDK v6.9.0 LinkGenerator.ResponseListener replaced CreateOneLinkHttpTask.ResponseListener

  • onResponse() is called when the user invite is created successfully.
  • onResponseError() is called when link generation fails.
  1. Pass listener to linkGenerator.generateLink():
    linkGenerator.generateLink(getApplicationContext(), listener);

Set the shortlink ID

The shortlink ID can be determined by the developer, by adding the paramter af_custom_shortlink to the LinkGenerator instance.

linkGenerator.addParameter("af_custom_shortlink", <value>);

Log invite link creation events

To log the invite link creation event:
Log the invite using logInvite():

HashMap<String,String> logInviteMap = new HashMap<String,String>();
logInviteMap.put("referrerId", <REFERRER_ID>);
logInviteMap.put("campaign", "summer_sale");

ShareInviteHelper.logInvite(getApplicationContext(), "mobile_share", logInviteMap);

logInvite results in an af_invite in-app event.



If you don't want to use a channel, you can use logEvent instead.

Set up UDL for user invite attribution

To set up UDL for user invite attribution:
Set up Unified Deep Linking (UDL). In DeepLinkListener.onDeepLinking(), retrieve the deep linking parameters created during the link generation step. In this example, the following properties are retrieved:

  • deep_link_value, using DeepLink.getDeepLinkValue()
  • deep_link_sub1, using DeepLink.getStringValue()
  • deep_link_sub2, using DeepLink.getStringValue()

See code: Java.

Reward referrers

In the following scenarios, User A invites User B to your app.

Reward referrers on install

Scenario: User B installs your app via User A's invite link.

User A's ID is available in DeepLinkListener.onDeepLinking() and in this example, is retrieved using DeepLink.getStringValue("deep_link_sub2"). Once you retrieve the ID, add it to the list of referrer IDs to be rewarded. It's up to you how to store and retrieve the list.

Reward referrers for user actions

Scenario: User B makes a purchase. You want to reward User A, who initially referred User B to your app, for the action.

To reward User A for User B's action:

  1. Retrieve User A's referrer ID and add it to one of the customizable in-app event parameters (for example, af_param_1):

     Map<String, Object> purchaseEventParameters = new HashMap<String, Object>();
     purchaseEventParameters.put(AFInAppEventParameterName.PARAM_1, <REFERRER_ID>);
     purchaseEventParameters.put(AFInAppEventParameterName.CURRENCY, "USD");
     purchaseEventParameters.put(AFInAppEventParameterName.REVENUE, 200);
     AppsFlyerLib.getInstance().logEvent(getApplicationContext(), purchaseEventParameters);
  2. On your backend, retrieve in-app event data

  3. Add the found referrer IDs to a list of users to be rewarded.

  4. When User A launches the app, check if their referrer ID is on the list of users to be rewarded and reward them if it is.



  • Steps 2-3 are not carried out by the mobile developer. Step 4 depends on how steps 2-3 are implemented.
  • A purchase event is just an example. This applies to any type of in-app event.