Public Methods

ReferralHero iOS Swift 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 object through which you can access all the APIs and get its response in the delegate methods.assign delegate of Viewcontroller class like below.

Use the following code to instantiate the RH class:

override func viewDidLoad() {
        super.viewDidLoad()
        RH.delegate = self
    }

Here are the delegate methods in which Response will be received:

extension CreateAccount: RHDelegate{
    func didReceiveAPIResponse(_ response: [String : Any], _ endPoint:                          String) {
        print("\(endPoint) \n + \(response)")
    }
    	
    func didFailWithError(_ error: Error, _ endPoint: String) {
        print("\(endPoint) \n + \(error)")
    }
}

1. Add Subscriber

Setting/Updating the ReferralParams details is an important step. This is how ReferralHero would be aware of the identity of a business user as classified by your app.

Step 1. Input Parameters

Parameters

referralParams

RHSubscriber

You can access the subscriber model to pass the input parameters.

Required Parameters : email, domain, name

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Here are more input parameters.

This class provides various methods to set several user referral details like name, email, device, etc. This class is used mainly to pass referral details data to the SDK while accessing its public method or while updating user information.

Step 2. ReferRHSubscriber 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.

Step 3. Implementation

To add a subscriber (for example, post a successful signup or login) simply call ReferralHero's RH.formSubmit() function and send the RHSubscriber information such as email address and name.

func formSubmit()
    {
        RH.formSubmit(param: RHSubscriber(email: "xyz@gmail.com", domain: "www.abc.com", name: “ABC"))
    }

2. Update Subscriber Details

This method is used to update various subscriber related data.

First, create a RHSubscriber model and set the user data you want to update.

Parameters

referralParams

RHSubscriber

Carrying the user data to be updated.

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 3. Implementation

To update the subscriber simply call ReferralHero's RH.UpdateSubscriber() function and send the RHSubscriber information such as email address and name.

  RH.UpdateSubscriber(param: RHSubscriber(email:    "abc@gmail.com", domain: "www.xyz.com", name: "abc"))

3. Get Subscriber Details

This method is used to retrieve Subscriber details. RH.getSubscriberDetail()

Step 1. Input Parameters

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

To get the subscriber details simply call ReferralHero's RH.getSubscriberDetail() function.

  RH.getSubscriberDetail()

4. Delete Subscriber

This method is used to Delete a newly Created Subscriber.

Step 1. Input Parameters

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

To delete the subscriber simply call ReferralHero's RH.DeleteSubscriber().

  RH.DeleteSubscriber()

5. Track Referral

Step 1. Method Usage

This method is used to track the referral conversion event. It means it is used to convert Referral status from pending to unconfirmed/confirmed.

If the referrer is present in the API request params, we will check the referral unique identifier in your campaign and, if found, the referral status will be updated and, if not found, we will create the referral and set the referral status.

If the referrer is not present in the API request params, we will check the referral unique identifier in your campaign and, if found, the referral status will be updated and, if not found, the referral will not be created.

Note:

  1. Your campaign must be set up as a custom event or a multi-step event otherwise, an error will return.

  2. If the referral is present in ReferralHero with pending status, a successful response custom_event_completed will return.

  3. If the referral unique identifier is not present in the ReferralHero, but the referrer unique identifier is present, a successful response custom_event_completed with the data of the new confirmed referral will return.

  4. If a referral exists but the referral status is not pending, the error custom event is already completed will return.

  5. 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 present will return.

  6. If the referral status is unconfirmed or confirmed, the error custom event is already completed will return.

  • uniqueIdentifier is a placeholder.

  • 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 RHSubscriber class Object

Step 2. Input Parameters

Parameters

referralParams

RHTrackReferral

You can pass email and name.

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 3. Implementation

Call RH.trackReferral(RHTrackReferral referralparams ). Use the following code to Track referral:

RH.trackReferral(param: RHTrackReferral(email: "xyz@gmail.com", name:"xyz"))

6. Capture Share

Step 1. Method Usage

This method is used to send the Share event to the RH. It means if a user called this method with any params like Facebook, messenger, etc. We capture this as a share in our system.

Step 2. Input Parameters

Parameters

referralParams

social

Add the Input para as string.

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 3. Implementation

Call the RH.clickCapture method of the RH class and pass “social” as an input parameter. Use the following code to Capture Share for a user:

RH.clickCapture(social: "facebook")

7. Get My Referrals

This method is used for retrieving all referrals of the specific subscriber.

Step 1. Input Parameters

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation.

Call RH.getMyReferrals() method of the RH class

Use the following code to Get My Referrals:

RH.getMyReferrals()

8. Get Leaderboard

This method is used for retrieving the campaign leaderboard. It will get the leaderboard from the Campaign specified in the Appdelegate.swift file.

Step 1. Input Parameters

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

Call the RH.getLeaderboard() method of the RH class to get the Subscriber Leaderboard.

RH.getLeaderboard()

9. Create Pending Referral

This method is used for creating a Referral with the Pending Status.

Step 1. Input Parameters

Parameters

referralParams

RHReferral

Carrying the referral data.

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

Create a ReferralParams class object and set the various user details to recognize the user matching your back-end system. To add a pending referral, simply call ReferralHero's RH.CreatePendingReferral() function and send the ReferralParams information such as email address and name.

RH.CreatePendingReferral(param: RHReferral(email: "xyz@gmail.com", name: "XYZ"))

10. Organic Track Referral

Step 1. Method Usage

If you would like to track referrals or add organic subscribers on the conversion page to your referral campaign, you can use this method.

If the Referrer code and uniqueidentifier are present, a Referral is created with the status unconfirmed/confirmed referral on the basis of the ‘Review Referral’ feature enabled/disabled.

If the Referrer code is not present but uniqueidentifier is present, an Organic Subscriber is created.

If the Referrer code is not present but a uniqueidentifier is present and a Referral already exists with the same uniqueidentifier in the campaign with pending status, the Referral Status will convert from pending to unconfirmed/confirmed on the basis of the ‘Review Referral’ feature enabled/disabled.

Step 2. Input Parameters

Parameters

referralParams

RHOrganicReferral

Add all the Input parameters as string.

email

name

referrer

hosting_url

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 3. Implementation

Create a RHOrganicReferral model and set the various user details to recognize the user matching your back-end system.

RH.OrganicTrackReferral(param: RHOrganicReferral(email: "abc@gmail.com", name: "ABC"))

11. Confirm Referral

Step 1. Method Usage

Confirm a referral. Useful when your campaign Goal is set to a "3-step conversion event" option and you want to confirm referrals when they complete your 3rd conversion event.

Only verified referrals can be confirmed. Trying to confirm a non-verified referral will return a subscriber_not_found error.

Step 2. Input Parameter

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 3. Implementation

Call the RH.ConfrimReferral method of the RH class.

RH.ConfirmReferral()

12. Get Referrer

Step 1. Input Parameter

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

Call the RH.ReferrerList method of the RH class. Use the following code to get the referrer:

RH.ReferrerList()

13. Get Rewards

Call the RH.RewardsList method of the RH class. Use the following code to get the rewards:

RH.RewardsList()

Last updated