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
    var referralData = new CustomReferralData();
    referralData.Add("key1", "value1");
    referralData.Add("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
    var inviteChannel = InviteChannelIds.Facebook;
    var inviteContent = InviteContent.CreateBuilder().Build();
    
    GetSocial.SendInvite(inviteChannel, inviteContent, referralData,
        onComplete: () => Debug.Log("Customized invitation via FACEBOOK was sent"),
        onCancel: () => Debug.Log("Customized invitation via FACEBOOK was cancelled"),
        onFailure: (error) => Debug.LogError("Customized invitation via FACEBOOK failed, error: " + error.Message)
    );
    
  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
GetSocial.GetReferralData(
    onSuccess: (referralData) => {
        if(referralData != null)
            Debug.Log("App started with Referral Data: " + referralData);
        else
            Debug.Log("No referral data found");
    },
    onFailure: (error) => Debug.LogError("Failed to retrieve referral data, error: " + error.Message)
);

No Referral Data after install from Facebook App Invite on iOS?

On iOS, make sure that you or any other 3rd party library (e.g. Branch.io) are not calling FB.Mobile.FetchDeferredAppLinkData method. Facebook SDK will return data associated with the deep link only on the first call. If someone will call it before GetSocial, you will not get Referral Data.

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
GetSocial.GetReferredUsers(referredUsers =>
    {
        if (referredUsers.Count > 0)
        {
            // current user invited others to the app
        }, 
        error =>  Debug.LogError("Failed to retrieve referred users, error: " + error.Message)
    }
);

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?

😀 🙁