---
updatedAt: 2025-06-12T11:30:19.000Z
agentTools:
  projectIndex: https://developers.viral-loops.com/llms.txt
---

# Overview

In depth documentation of the ViralLoops Client Side Library

## `window.addEventListener("vlReady", callback)`

To make sure that the `ViralLoops` global object is loaded you can listen for the global `vlReady` event which is going to fire after the Viral Loops snippet load has been completed.

***

## `ViralLoops.getCampaign()`

Get the *default* `campaign` loaded on the current page.

```javascript
const campaign = await ViralLoops.getCampaign();
```

You can have multiple campaigns loaded on the current page. Use `ViralLoops.campaigns` to get all loaded campaigns within the page.

```javascript default Campaign
const campaign = await ViralLoops.getCampaign();
```
```javascript with specific Campaign ID
const campaign1 = await ViralLoops.getCampaign("Your Campaign ID")
const campaign2 = await ViralLoops.getCampaign("Your Other Campaign ID")
```

<br/>

## Campaign Methods and Attributes

## `campaign.identify(user)`

The `user` object looks like this:

```javascript
const user = {
  email: "filippos@viral-loops.com", // required
  firstname: "Filippos", // optional
  lastname: "Filippos", // optional
  extraData // optional
}
```

You can use the response to acquire the user's referral code.

```javascript
let response = await campaign.identify(user) // the referrer is automatically parsed
let referralCode = response.referralCode
let referralUrls = response.referralUrls
```

> 📘 The `user.extraData` are custom data you want to capture about the participant. These are only visible on a special campaign export that we provide on demand.

> ❗️ Unfortunately, most CMSs (like Unbounce, Lead Pages, Instapage, Squarespace etc.) don’t allow you to run code after form submission so this solution won’t work there. Most form plugins on WordPress also don't support running code after submission.

***

## `campaign.getReferrer()`

This method parses the URL for parameters like `refCode`, `referralCode` and `ref` to derive the `referrer` of the `participant` if there's one.

***

## `campaign.setReferrer({ referralCode, refSource })`

Use this method to programmatically set the referrer.

```javascript
let referrer = { referralCode: "abcde" }
campaign.setReferrer(referrer)
```

***

## `campaign.getRank()`

Get the participant's rank

```
await campaign.getRank()
```

***

## `campaign.getOrder()`

Get the order of a participant.\
For example if they joined the campaign first, their order will be 1, if they joined second their order will be 2.

```
let order = await campaign.getOrder()
```

***

## `campaign.getUser()`

Get the current user of the campaign

***

## `campaign.info`

Get the campaign's info and configuration object

```javascript
const campaignInfo = campaign.info
```

***

## `campaign.getPendingRewards()`

Supported Templates: Refer a Friend\
Get the pending rewards of a participant.

```javascript
const pendingRewards = await campaign.getPendingRewards();
```

## `campaign.getGivenRewards()`

Supported Templates: Refer a Friend\
Get the given rewards of a participant.

```javascript
const pendingRewards = await campaign.getGivenRewards();
```

## `campaign.logout()`

Clears the user data