Public Methods
ReferralHero Kotlin / Java SDK
ReferralHero provides a very simple and efficient approach for an application to communicate with our SDK.
A whole set of public methods exists within the SDK using which you can easily access most of the data, execute various SDK tasks, invoke from a large set of APIs, etc.
RH is the main SDK class and point of interface for an application to communicate with the SDK.
Most of the methods you will use will be from this class, so it's very important to instantiate it before actually starting to use it. Though it can be instantiated from any class, it is highly recommended to do so on the very first screen of your app, so that the SDK would be ready to use by the time your app transits to the main screen.
Use the following code to instantiate the RH class:
RH rh = RH.getInstance();
// or
RH rh = RH.initRHSDK(context, null, null);val rh = RH.instance
// or
val rh = RH.initRHSDK(context, null, null);Below is a full list of public methods provided by the ReferralHero SDK, you can check them out to know their use case, return type, and input parameters:
1. Add Subscriber
This method is most commonly used to add an organic subscriber or create a referral (if identified) after a user successfully signs up or logs in to your app.
When using this method please take note of your Campaign Goal as our tracking logic will depend on if you are tracking a single or multi-step conversion event.
Parameters
referralParams
RHSubscriber
Carrying the user data to be updated.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution; else NULL
Step 1. ReferralParams Model
Method
Description
transaction_id (String)
The unique ID of the transaction. Useful for tracking referrals for purchases.
conversion_category (String)
The type of referral. Useful for creating reports.
conversion_value (String)
The monetary value of the referral.
device (String value)
The device used by the subscriber to sign up. Used for analytics.
email (String value)
The email of the subscriber.
domain (String)
The URL for the referral link.
name (String)
The name of the subscriber.
referrer (String)
Set a referrer for the subscriber by providing the referrer's referral code or email.
source (String)
The source of the subscriber. Used for analytics.
crypto_wallet_address (String)
The crypto wallet address
extra_field (String)
The extra field of the subscriber.
extra_field2 (String)
The extra field 2 of the subscriber.
points (String)
The number of points for the subscriber. Only applicable for "contest" campaigns.
phone_number (String)
The Phone Number of subscriber
double_optin (string value)
If set to false, the subscriber will not receive a confirmation email.
status (String)
Use 'custom_event_pending' to set the referral status to pending
Step2.
Create a ReferralParams class object and set the various user details to identify the user matching your back-end system.
To add a subscriber (for example, post a successful signup or login) call ReferralHero's rh.formSubmit() function and send the ReferralParams information such as email address and name. The minimum values you should send for the endpoint to work are the following:
To identify and create a referral, you must also send either the setReferrer OR the required mobile params so that our matching algorithm can automatically identify a referral.
NOTE: The mobile parameters must be sent in the correct format for our system to automatically identify and create a referral. See the Getting Started section here.
The accepted Screen Size formats are:
See here for more parameters of ReferralParams Class.
Step 3.
Invoke rh.formSubmit(RHReferralCallBackListener callback, ReferralParams referralparams ) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
It is advised that you INITIALIZE the SDK in the Application class, so that we may ensure a smooth user experience check out this SDK initialize steps.
Use the following code to Add Subscriber:
Subscriber Data Class Sample Response
2. Add Pending Referral
This method is most commonly used to create a referral entering the 1st step of your multi-step conversion event funnel (i.e. after a referred user successfully signs up for your app). If you want us to automatically add every user to your campaign and determine if the user is a referral or not, use the Add Subscriber method instead. This logic only checks for referrals:
To add a pending referral, simply call ReferralHero's RH.pendingReferral() function and send the user information such as email address, name, etc.
Parameters
referralParams
ReferralParams
Carrying the referral data.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Create a ReferralParams class object and set the various user details to identify the user matching your back-end system.
To add a pending referral, simply call ReferralHero's rh.pendingReferral() function and send the ReferralParams data.
The minimum values for this endpoint to work:
OR:
Step 2.
Invoke rh.pendingReferral(RHReferralCallBackListener callback, ReferralParams referralparams) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
Use the following code to Add Pending Referral:
Subscriber Data Class Sample Response
3. Track Referral
This method is used for tracking a referral conversion event (i.e. a purchase, but can be any conversion event).
Note:
Your campaign must be set up as a custom event or a multi-step event otherwise, an error will return.
If the referral is present in ReferralHero with pending status, a successful response
custom_event_completedwill return.If the referral unique identifier is not present in the ReferralHero, but the referrer unique identifier is present, a successful response
custom_event_completedwith the data of the new confirmed referral will return.If a referral exists but the referral status is not pending, the error
custom event is already completedwill return.If the referral unique identifier is not present in ReferralHero and the referrer is also not provided in the API, the error
referer is invalid or not presentwill return.If the referral status is unconfirmed or confirmed, the error
custom event is already completedand will return.
When tracking referrals on your App you should ALWAYS send the ACTUAL unique identifier (email, phone number, crypto wallet address, or other ID) of the user in referralParams class Object.
Parameters
referralParams
ReferralParams
Carrying the user data to be updated.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Create a ReferralParams class object and set the various user details to identify the user matching your back-end system.
If the referral is pre-existing in the campaign, the minimum value for this endpoint to work:
Step 2.
Call rh.trackReferral(RHReferralCallBackListener callback, ReferralParams referralparams ) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
Use the following code to Track Referral:
Subscriber Data Class Sample Response
4. Confirm Referral
Use this method when your Campaign Goal is set to track three conversion events and you want to confirm a referral when your third conversion event occurs (complete profile, upgrade to a paid plan, end of the trial, etc).
Note: Only verified referrals can be confirmed. Trying to confirm a non-verified referral will return a subscriber_not_found error.
Parameters
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Invoke rh.confirmReferral(RHReferralCallBackListener callback) method of the RH class to Confirm Subscriber API calls, passing an RHReferralCallBackListener instance.
Use the following code to Confirm Referral:
Subscriber Data Class Sample Response
5. Organic Track Referral
If you would like to add an organic subscriber or a track referral on the conversion page to your referral campaign, you can use the following method. This method would most commonly be used if the user has not been previously added to your campaign and instead directly passes through a post-checkout/subscribe event.
Parameters
referralParams
ReferralParams
Carrying the referral data.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Create a ReferralParams class object and set the various user details to identify the user matching your back-end system.
To add an organic referral track, simply call ReferralHero's rh.organicTrackReferral() function and send the ReferralParams information such as email address and name.
Step 2.
Invoke rh.organicTrackReferral(RHReferralCallBackListener callback, ReferralParams referralparams) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
Use the following code for Organic Track Referral:
Subscriber Data Class Sample Response
6. Update Subscriber Details
This method is used to update various subscriber data like username, address, etc.
First create a ReferralParams class instance and set the user data you want to update using its setter methods, then pass that instance in this method.
Parameters
referralParams
ReferralParams
Carrying the user data to be updated.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Follow this step (Add a Subscriber - previously described)
Step 2.
Call rh.updateSubscriber(RHReferralCallBackListener callback, ReferralParams referralparams ) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
Subscriber Data Class Sample Response
7. Get Subscriber Details
This method is used to retrieve subscriber details.
Parameters
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Call rh.getSubscriber(RHReferralCallBackListener callback) method of the RH class to get Subscriber API calls, passing the RHReferralCallBackListener instance.
Subscriber Data Class Sample Response
8. Delete Subscriber
This method is used to delete a created subscriber.
Parameters
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Call rh.deleteSubscriber(RHReferralCallBackListener callback) method of the RH class to get Subscriber API calls, passing the RHReferralCallBackListener instance.
Subscriber Data Class Sample Response
9. Capture Share
This method is used to send a user share event to ReferralHero. When this method is called including the params (i.e. facebook, messenger, etc.), we capture a share in our analytics system.
Parameters
referralParams
ReferralParams
Carrying the user data to be updated.
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Call rh.captureShare(RHReferralCallBackListener callback, ReferralParams referralparams ) method of the RH class to Add Subscriber API calls, passing the ReferralParams object created in the previous step and an RHReferralCallBackListener instance.
Use the following code to Capture Share:
Subscriber Data Class Sample Response
10. Get My Referrals
This method is used for retrieving all referrals of the specific subscriber.
Parameters
callback
RHMyReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Call rh.getMyReferrals(RHMyReferralCallBackListener callback) method of the RH class to get Subscriber API calls, passing the RHReferralCallBackListener instance.
Use the following code to Get My Referrals:
Get My Referral Sample Response
11. Get Leaderboard
This method is used for retrieving the leaderboard from the campaign UUID set in the AndroidManifest.xml file.
Parameters
callback
RHLeaderboardReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Call rh.getLeaderboard(RHLeaderboardReferralCallBackListener callback) method of the RH class to get Subscriber API calls, passing the RHLeaderboardReferralCallBackListener instance.
Use the following code to Get Leaderboard:
Get Leaderboard Sample Response
12. Get Referrer
This method is used to retrieve the referrer of a user. By calling this method, you would know if someone was a referral or not, and then could:
Apply a discount code automatically to the checkout process
Personalize text shown on a page
Parameters
callback
RHReferralCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Create a ReferralParams class object and set the various user details to identify the user matching your back-end system.
Minimum parameters for this endpoint to work:
NOTE:
The mobile parameters must be sent in the correct format for our system to automatically identify a referral. See the Getting Started section here.
Step 2.
Invoke rh.getReferrer(RHReferralCallBackListener callback) method of the RH class to get referrer Subscriber data API calls, passing an RHReferralCallBackListener instance.
Use the following code to Get Referrer data:
Get Referrer Sample Response
13. Get Rewards
Use this method to Get Rewards unlocked by a specific subscriber.
Parameters
callback
RHRewardCallBackListener
Callback interface if you want to get the callback after API execution ; else NULL
Step 1.
Invoke rh.getRewards(RHRewardCallBackListener callback) method of the RH class to get all rewards list data API calls, passing an RHRewardCallBackListener instance.
Use the following code to Get Rewards data:
Get Rewards Sample Response
Last updated
Was this helpful?