Client Side SDK

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.

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.

const campaign = await ViralLoops.getCampaign();
const campaign1 = await ViralLoops.getCampaign("Your Campaign ID")
const campaign2 = await ViralLoops.getCampaign("Your Other Campaign ID")

Campaign Methods and Attributes

campaign.identify(user)

The user object looks like this:

const user = {
  email: "[email protected]", // required
  firstname: "Filippos", // optional
  lastname: "Filippos", // optional
  extraData // optional
}

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

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.

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

const campaignInfo = campaign.info

campaign.getPendingRewards()

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

const pendingRewards = await campaign.getPendingRewards();

campaign.getGivenRewards()

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

const pendingRewards = await campaign.getGivenRewards();

campaign.logout()

Clears the user data