# Javascript SDK

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

```

{% hint style="info" %}
If you have multiple campaigns, campaign Id will be automatically tracked by referral code of the visiting user. If the referral code is missing, it will fall back to either user provided campaign Id or Id passed into the script. \
Eg. window\.Rocket.getCampaign("summer-promo-2024").addParticipant(userData);
{% endhint %}

**Verify Installation**&#x20;

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.

<figure><img src="https://lh7-us.googleusercontent.com/jlyV3T4meKyS_sv7PfiT_iC9tztnvu-SwoxciSqoNf1w1Fh752lZkRezxChyA3In8IYXgIlt4rQEzj2qB_V1sW96dKefhSYvie2vHPNBPPciV4DbkKuOZVdBY35845tPRMFpMU1TyoGE8oJ8cFZ_B4g" alt=""><figcaption></figcaption></figure>

## API Reference

### 1. Get Campaign Detail

Retrieves the details of your campaign.

#### Method Signature

<figure><img src="https://lh7-us.googleusercontent.com/_C5OtNyhOOZQZPs2NFFUtsnrH7gvnOLFeFiFrGi_A03arR-0ub3tvJTX6o50ZtYw-nVzE4wCLpC6mdMDhsEhNC__GvNIcR8IX5fOQoVUnF0YM6CZSF590XUxR0zwXGTT0OZHUUBGX5fRFEuv6U9rwyA" alt=""><figcaption><p>Returns a<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises"> Promise</a> that resolves with an<a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics"> Object</a> containing limited campaign data.</p></figcaption></figure>

**Retrieving Campaign Using a Promise**

<figure><img src="https://lh7-us.googleusercontent.com/yRm2XrQs_0GjNDirqT7eHVAScVbVGLvsqY-lGNJJbf06PZH5_eMA6JgGQ5PJSBmFXlfKzOFJPuLuwOsvwxkOOcvLT7_cfBm2g6IGO4gycSUAJ0r5CxB1Pqt1ibcZ2J3X5TorC_X3loUml2HqaOx5CMw" alt=""><figcaption></figcaption></figure>

#### Example Response

<figure><img src="https://lh7-us.googleusercontent.com/qjTr7TgImBx7EtoJ-ivZABSI30fVm8z4_L7iWk6QZB2lL3YsnG9Pew6zdbbo0SX6XO-_D1RdlIYeYIjZ7t_PhILL5NtXPiO8J-jr4afcO5NIeTcZd1Q8pZGpFHTiFm2iDiH7Lgwj2UkG2Lkxa702Ujk" alt=""><figcaption></figcaption></figure>

### 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**

<figure><img src="https://lh7-us.googleusercontent.com/BB6PHV26aT1E1TyOTISXDNQsUZCd6KUXzK2vcATGgAsiMkiika50nzylcfSY5vH73X3MOD-cvVXLYZVm1dRtqxnfj5zSCxQcLTeMlCVg3LhiYUSvSL2hW0r1wopx1oRa3a6ur9u7mUioIJTj1WFIAyo" alt=""><figcaption></figcaption></figure>

**Parameters**

| Parameter | Data Type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| --------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data      | Object    | <p>An Object containing the participant email and any other additional data to include for the participant. </p><p><br>Example Object: <br>{ </p><p>email: '<john@gmail.com>', fName: 'John', <br>lName: 'Taylor', <br>referredByCode{optional]: 'dkghdgzd',</p><p>referredByEmail\[optional]:'<mike@gmail.com>' </p><p>}<br></p><p>Referred by fields are optional. If a referral is detected via a cookie, it will be automatically associated with this participant.</p> |

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

<figure><img src="https://lh7-us.googleusercontent.com/yq_R7hIo7yAs-BDc4p_x54KD0o1TMgT0z8rSXkY9T3vd9yxlNelNdxrxpBvvjHuE8Xj_L2VoFCBX2tq_P-zJykPCLFMZsZm3mcyMCLF1LM-ZMcATb5Q9ZXqDsFgfbs5nm3OLvJ-T_F5Ua8Ew4x7POhY" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/fcjgcWjV_pAbZzcMzsh3Rc8ugtn8ZyCr-7qTpgL1mP44FZLmzndhXp3f6lwS9lJrWlSgqpeipCq9wytH5bW1_Cm3m0S4NNWAKWlmCuM2SqP2i2ZikSI5BL4iGyqf0Hh17gNETul7ZSxPl5b51YXT_N0" alt=""><figcaption></figcaption></figure>

**Example Response**

<figure><img src="https://lh7-us.googleusercontent.com/4CMKsMxNIxNaguAOsu93OYjVL8AnVEWHZDiNzxDEcnLwo-3ZOCiV6C1SXwUqmqZxhb3bxDi1Dykn2UsJPA0Ct_chzm0S-pRomUAY-g0ILfBNRBu2qBFx12cvIjDq2zNKHU0b9Ekt301QicCCSvHRl4w" alt=""><figcaption></figcaption></figure>

### 3. Get Participant Detail

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

#### Method Signature

<figure><img src="https://lh7-us.googleusercontent.com/ZkZFRk8dMWs6uHv3K1ev8owXgIik7pmh2NxlEdETKIh2ygb_eeQTHtQtjfQNGCpJ0tIULKB0LhGfLxlXEJKJFxSepvpUGxUDdqcRMn3qZWdqG4DdcBnXAUGzwrFuQfY4a11DPxt95IW5XaTjr7EJzOU" alt=""><figcaption><p><br></p></figcaption></figure>

**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.&#x20;

  <figure><img src="https://lh7-us.googleusercontent.com/eTqy5bJh7nwmnJb7LyyQrJqGivdAdpGZL2A92sBIQoEl008PalVM7sP3Ytr3a9LOUpJ9vOWNdZ3Q7dlCLCR8LXFSF8cmC9Ni_4_C_gm7vbbmnD3gEOuyvVkQF83Vfwt1adudsAeVLsG3cAmuv_dkd9E" alt="" width="375"><figcaption></figcaption></figure>
* #### code: The referral code of the participant.&#x20;

  <figure><img src="https://lh7-us.googleusercontent.com/sQxLE7yyZfpe2vhDGabjyS-msYRQnAFxg7aIdEKIahOKWoHwS9FClL3EfKan4oQmDf33hhYCU6f94z_8b9ZtfvLNpBfz9sX0lyz1L-VmF51tnWJgflZlhu3yuOk3iVOCZwKjF5Eq9G39pc0ufoyADdk" alt="" width="375"><figcaption></figcaption></figure>

#### Example

#### Retrieving Participant Using a Promise

<figure><img src="https://lh7-us.googleusercontent.com/MwTf9WzccuNfOgAfIYUXXVydSNzJPHEoCK6Yb2Hq9a-7PjDnQ_IVd20mfmHAdISOjGoMdTJSk3BRGKMwRscf8iui4xaRWaU9sqIEYD7iOerTpLApQjvwDk4WsABTPAi1N2TEH4bK40dfPyX_fIxf_iM" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/7JUhC4i5iELx2N1ZgCnO_Q5H1zFTOc4glmpZ4lbJ3gL-BvY3EitpCAMnAL1zlT-SkHUtVZhypV86lX48yyohcylaO7W6Z-gWdIE4SvScHf7bH_4my8cAOnMGpsbRzqVdhwjl_PXWiCJh6V6A6yAjAq0" alt=""><figcaption></figcaption></figure>

**Example Response**

<figure><img src="https://lh7-us.googleusercontent.com/h_9IGYOpaTXjwdlaU1cgPMB9dUo0ribe031B0Xw7sHfPL_nMez7HsSa2rEYNEv-beieeiFfCDhg-6njCtv_2S6yfG6Svt8d6lojDUeDY8INQss2uAp97Um3R5i2WAq4RF9S2ZA4s9l9ZI5i303MLs8s" alt=""><figcaption></figcaption></figure>

### 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.&#x20;

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.&#x20;

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    | <p>(Required) An Object containing the email of the participant.<br>(Optional) Amount spent by the participant.<br>(Optional) rewardReferee: Generate a reward for the referee in addition to the referrer</p> |

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

<figure><img src="https://lh7-us.googleusercontent.com/fMphNjboa4Pn66_UKWu6sYibxSdXotmG-yNUhXkfk_EMpgAAKkQSpk6hX0CY-El0u66fuIa_e9a5OIQLAGoaIOez1WFK4VgBKkr0LuYIHj9zPnTnz7nLSc2bwRlBR6UotDEfMx3ge2Vpbm44RXB1Fc8" alt=""><figcaption></figcaption></figure>

#### Example Response

<figure><img src="https://lh7-us.googleusercontent.com/h_9IGYOpaTXjwdlaU1cgPMB9dUo0ribe031B0Xw7sHfPL_nMez7HsSa2rEYNEv-beieeiFfCDhg-6njCtv_2S6yfG6Svt8d6lojDUeDY8INQss2uAp97Um3R5i2WAq4RF9S2ZA4s9l9ZI5i303MLs8s" alt=""><figcaption></figcaption></figure>

### 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:**

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe5mpw7zUx2jeMq5q-Vot2IcsFhCqvD0XzZ6NS5avnWp09KuZRy6a0c-HSNuzffGBbInImqkvm_WolXO_SNQGKRTPhE5inHFsU0cXfzRooyqg74QoWy8KoLMPjdJhkznRPepGCRP8HhYweTudWLjum2mYYc?key=5QucuvqSn00zFJ8_gLk0Ag" alt=""><figcaption></figcaption></figure>

### 6. Validate Referrer Code

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

**Example Usage:**<br>

<figure><img src="https://346708387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJpvWNOwMd3hfowlhBXaA%2Fuploads%2FwNDlpz7JeOGg0YaRhd8n%2FScreenshot%202025-02-10%20at%2010.34.07%20AM.png?alt=media&#x26;token=505a6f55-8d2b-4802-98be-e5ecb0b0d08f" alt=""><figcaption></figcaption></figure>
