Javascript SDK

Referral Rocket makes it easy to interact with your data via our Javascript SDK. This article explains the Referral Rocket JavaScript Web APIs, showing how to use each method with examples.

Getting Started

Install Referral Rockets library that attaches the Rocket library to the global window. Replace the campaign ID with your campaign ID. Place this script in the <head> section of your website.

// Add this script in the HEAD tag
<script type="text/javascript" campaign-id="YOUR-CAMPAIGN-ID" defer src="https://app.referralrocket.io/widget/widgetIndex.js"></script>

Verify Installation

You can confirm that the Rocket object is available by opening the browser window and enter window.Rocket. If the installation is successful, it will return an instance of the Referral rocket object.

API Reference

1. Get Campaign Detail

Retrieves the details of your campaign.

Method Signature

Returns a Promise that resolves with an Object containing limited campaign data.

Retrieving Campaign Using a Promise

Example Response

2. Add Participant

The Add Participant method allows you to add a new participant—either referred or direct. A notable feature of this method is that passing a referral code or referral email is optional. The system will automatically detect the referral from the stored cookie and add it to the participant’s information.

Method Signature

Parameters

Parameter
Data Type
Description

data

Object

An Object containing the participant email and any other additional data to include for the participant.

Example Object: {

email: 'john@gmail.com', fName: 'John', lName: 'Taylor', referredByCode{optional]: 'dkghdgzd',

referredByEmail[optional]:'mike@gmail.com'

}

Referred by fields are optional. If a referral is detected via a cookie, it will be automatically associated with this participant.

Description of Object Properties

  • email: The email of the participant.

  • fName: The first name of the participant.

  • lName: The last name of the participant.

  • referredByCode [optional]: The referring customers unique code, typically used to track the referring participant. Only required for referred participants.

  • referredByEmail [optional]: The referring customers email, typically used to track the referring participant. Only required for referred participants.

Examples

Adding Participant with Object Using a Promise

Example Response

3. Get Participant Detail

Retrieves limited details of an existing participant by their email or Referral-code.

Method Signature

Parameters

Parameter

Data Type

Description

data

Object

(Required) An Object containing either the email or the referral code of the participant to retrieve.

Description of Object Properties

  • email: The email of the participant.

  • code: The referral code of the participant.

Example

Retrieving Participant Using a Promise

Example Response

4. Qualify Participant

The Qualify Participant method is used when an user makes a payment or performs a reward qualifying event (such as sign up, purchase, etc) indicating a referral has occurred and referrer is eligible for reward.

The system takes the email address of a referred participant and marks their qualifying event (sign up, purchase, etc) as complete in the campaign. This will trigger the referring participants to be eligible for a reward.

The system will automatically detect the referral from the stored cookie and add it to the participant’s information.

Method Signature

const campaign = window.Rocket.getCampaign();
campaign.qualifyParticipant({
    email: 'mike@gmail.com',
    amountPaid; 150.00,
    rewardReferee: false
});

Parameters

Parameter

Data Type

Description

data

Object

(Required) An Object containing the email of the participant. (Optional) Amount spent by the participant. (Optional) rewardReferee: Generate a reward for the referee in addition to the referrer

Description of Object Properties

  1. email

  2. amountPaid

  3. rewardReferee

{
"email": "mike@gmail.com",
"amountPaid": 150,
"rewardReferee": false
}

Example

Fulfill the reward event api using a promise.

Example Response

5. Get Referral Code

Using the getReferrralCode() function returns the referral code if available. If a referral code is not found, it will return null.

Example Usage:

6. Validate Referrer Code

Using the validateCode(code) function returns a boolean if the referral code if valid.

Example Usage:

Last updated