Sending and Receiving Referral Data

You can attach any key-value data to GetSocial Smart Invites and Smart Links. Receiving user can get the data from the invite or link even if the was was just installed from the store.

Prerequisite

Send Referral Data

Referral Data is map of string-string key-value pairs that are attached to the Invite Link. It is possible to attach custom data when sending invitation via GetSocial Data API and GetSocial UI. The code below shows how to do so:

  1. Create CustomReferralData object with key-value pairs you want to attach to the Invite Link:

    1
    2
    3
    CustomReferralData referralData = new CustomReferralData();
    referralData.put("key1", "value1");
    referralData.put("key2", "value2");
    
  2. If you are building invitation UI on your own, use GetSocial Data API to send invitation with CustomReferralData attached:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    String inviteChannel = InviteChannelIds.FACEBOOK;
    InviteContent inviteContent = InviteContent.createBuilder().build();
    
    GetSocial.sendInvite(inviteChannel, inviteContent, referralData, new InviteCallback() {
        @Override
        public void onComplete() {
            Log.i("GetSocial", "Invitation with referral data via FACEBOOK was sent");
        }
    
        @Override
        public void onCancel() {
            Log.i("GetSocial", "Invitation with referral data via FACEBOOK was cancelled");
        }
    
        @Override
        public void onError(Throwable throwable) {
            Log.e("GetSocial", "Invitation with referral data via WHATSAPP failed, error: " + throwable.getMessage());
        }
    });
    
  3. Or, if you are using GetSocial UI, attach CustomReferralData to the view:

    1
    2
    3
    GetSocialUi.createInvitesView()
            .setCustomReferralData(referralData)
            .show();
    

Retrieve Referral Data

It is possible to retrieve Referral Data attached to the Invite Link in two cases:

  • On the first launch after the app was installed from clicking on the GetSocial Invite or Smart Link.
  • When the app was opened from clicking on the GetSocial Invite or Smart Link.

The code below show how to do it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
GetSocial.getReferralData(new FetchReferralDataCallback() {
    @Override
    public void onSuccess(@Nullable ReferralData referralData) {
        if(referralData != null)
            Toast.makeText(MainActivity.this, "App started with Referral Data: " + referralData, Toast.LENGTH_LONG).show();
        else
            Toast.makeText(MainActivity.this, "No Referral Data found", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onFailure(GetSocialException error) {
        Toast.makeText(MainActivity.this, "Failed to retrieve Referral Data, error: " + error, Toast.LENGTH_LONG).show();
    }
});

Returned referral data contains custom data attached to the link, metainformation about the channel, user who sent an invitation, etc. For a full list of available properties check the ReferralData reference.

Retrieve Referred Users

You can also check the list of invited users of current user:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
GetSocial.getReferredUsers(new Callback<List<ReferredUser>>() {
    @Override
    public void onSuccess(List<ReferredUser> result) {
        if (result.size() > 0) {
            // current user invited others to the app
        }

        @Override
        public void onFailure(GetSocialException exception) {
            Toast.makeText(MainActivity.this, "Failed to retrieve ReferredUsers, error: " + error, Toast.LENGTH_LONG).show();
        }
});

ReferredUser object contains user details, including installationDate, which is the date when the invited user installed the app.

This way for example you can reward your users for inviting other users:

  1. Read last reward check date from local storage.
  2. If ReferredUser object installationDate value is after reward check date, you can give reward.
  3. Update reward check date to current date.

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁