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 by 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

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.

GOAL: One Conversion Event If you have your Campaign Goal set up to track one conversion event, the following tracking logic will take place:

  • If a referral, a referral will be automatically created and set to Confirmed in the correct campaign.

  • If not a referral, an organic subscriber will be created in the campaign UUID specified.

  • If the subscriber exists in our database, the subscriber will be 'identified'. Data is not overwritten. Additional data will be created.

GOAL: Two or Three Conversion Events If you have your Campaign Goal set up to track two or three conversion events, the following tracking logic will take place:

  • If a referral, a referral will be created and set to Pending in the correct campaign.

  • If not a referral, an organic subscriber will be created in the campaign UUID specified.

  • If the subscriber exists in our database, the subscriber will be 'identified'. Data is not overwritten.

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.

status (String)

Use 'custom_event_pending' to set the referral status to pending

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", //Required value, capture this from user
        domain: "www.abc.com", //Required value, should match the default referral link set within your RH account
        name: “ABC", //Optional but recommended, capture this from user
        referrer: "53f8acf7", //Optional value, only necessary if the user will provide the referrer code directly, otherwise the below 4 params are required
        IPAddress: "201.202.203.205", //Required value, necessary if you want RH to automatically identify & create a referral without the user providing the setReferrer params, see below
        device: "iPhone", //Required value, see below
        screen_size: "370.0 x 480.0", //Required value, see below
        os_type:"iOS", //Required value, see below
        status: "custom_event_pending" //Use 'custom_event_pending' to set the referral status to pending
        ))
    }

The minimum values you should send for the endpoint to work are the following:

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

To identify and create a referral, you must also send either the Referrer value OR the required mobile params so that our matching algorithm can automatically identify a referral.

// Example Data
“os_type”: “iOS”,
“device”: “iPhone 14”,
“ip_address”: “123.156.219.010",
“screen_size”: “432.0 x 960.0",

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:

“screen_size”: "393*852"",
“screen_size”: "393 x 852",
“screen_size”: “393x852",
“screen_size”: “393.0 x 852.0",
// in case you need to hard code values

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:

Tracking Logic

GOAL: Two or Three Conversion Events

Your campaign Goal must be set up to track two or three conversion events, and then the following tracking logic will take place:

  • If a referral, a referral will be automatically created and set to Pending in the correct campaign.

  • If not a referral, no subscriber will be created.

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", //Capture this from user
        domain: "www.abc.com", 
        name: “ABC", //Capture this from user
        referrer: "53f8acf7", //Optional value, only necessary if the user will provide the referrer code directly, otherwise the below 4 params are required
        IPAddress: "201.202.203.205", //Required value, necessary if you want RH to automatically identify & create a referral without the user providing the Referrer params, see below
        device: "iPhone", //Required value, see below
        screen_size: "370.0 x 480.0", //Required value, see below
        os_type:"iOS", //Required value, see below
        status: "custom_event_pending" //Use 'custom_event_pending' to set the referral status to pending
        )))

The minimum values you should send for the endpoint to work are the following:

param: RHReferral(
        email: "xyz@gmail.com", 
        referrer: "M12345fc2")

OR

param: RHReferral(
        email: "xyz@gmail.com", 
        IPAddress: "201.202.203.205",
        device: "iPhone",
        screen_size: "370.0 x 480.0",
        os_type:"iOS")

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.

3. Track Referral

This method is used for tracking a referral conversion event (i.e. a purchase, but can be any conversion event).

Tracking Logic:

  • If a referral and pre-existing in the campaign as Pending

OR

  • If a referral and setReferrer or mobile pramas are provided, a referral is automatically created in the correct campaign and

The Referral Is Set To:

  • Confirmed (if tracking two conversion events)

  • Unconfirmed (if tracking three conversion events)

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.

  • 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 1. Input Parameters

Parameters

referralParams

RHTrackReferral

You can pass email and name.

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

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

RH.trackReferral(param: RHTrackReferral(
email: "xyz@gmail.com", //Required value, capture this from user
name: “ABC", //Optional value, capture this from user
referrer:"52f7acf8", //Optional value, only required if the user does not exist in the campaign
IPAddress: "201.202.203.205",//Optional value, only required if the user does not exist in the campaign
device: "iPhone",//Optional value, only required if the user does not exist in the campaign
screen_size: "370.0 x 480.0",//Optional value, only required if the user does not exist in the campaign
os_type:"iOS"//Optional value, only required if the user does not exist in the campaign
))

If the referral is pre-existing in the campaign, the minimum value for this endpoint to work:

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

If the referral is NOT pre-existing in the campaign (and you want to identify and create a referral), you must send either the setReferrer OR the required mobile parameters in the correct format so that our matching algorithm can automatically identify a referral. See the Getting Started section here.

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).

Tracking Logic:

  • If a referral and pre-existing in the campaign as Unconfirmed

The Referral Is Set To:

  • Confirmed (if tracking three conversion events)

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

Step 1. Input Parameter

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

Step 2. Implementation

Call the RH.ConfrimReferral method of the RH class.

RH.ConfirmReferral()

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.

Tracking Logic:

  • If a referral and pre-existing in the campaign as Pending

OR

  • If a referral and setReferrer or mobile params are provided, a referral is automatically created in the correct campaign and

The Referral Is Set To:

  • Confirmed (if tracking two conversion events)

  • Unconfirmed (if tracking three conversion events)

OR

  • If not a referral, an organic subscriber is created in the campaign UUID specified.

Step 1. 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 2. 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"))

If the referral is NOT pre-existing in the campaign (and you want to identify and create a referral), you must send either the setReferrer OR the required mobile parameters in the correct format so that our matching algorithm can automatically identify a referral. See the Getting Started section here.

6. 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"))

7. 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()

8. 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()

9. 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")

10. 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()

11. 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()

12. Get Referrer

Step 1. Input Parameter

Parameters

Response

didReceiveAPIResponse

didFailWithError

In RHDelegate methods you will get the response model

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. Implementation

Call the RH.GetReferrer() method of the RH class. Use the following code to get the referrer:

RH.GetReferrer()

13. Get Rewards

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

RH.RewardsList()

Last updated