Introduction

In the milestone referral template (or any other Viral Loops sign-up tracking template) a successful referral happens when the invitee makes a registration.

In some cases a different behavior might be desired.

For Example:

  • User makes a purchase
  • After a custom conversion action

For cases like these you can use our API to completely control and change the flow of the referral program.

Let's get to it!

Note: the following can be applied to any Viral Loops sign-up tracking template.

On sign-up

First you will need to capture the 2 query parameters that all users have when they land on your page through a referral invite.

  • referralCode
  • refSource

These should be saved alongside any new user that registers on your platform so their referrer can be properly rewarded later when they make their action.

After a successful action 

After a successful action the following API call should be run:

POST https://app.viral-loops.com/api/v2/events

A header Content-Type: application/json is needed.

Request parameters

{
    "apiToken":"MY_TOKEN",
    "params":{
        "event":"registration",
        "user":{
            "firstname": "the user's firstname",
            "lastname": "the user's lastname",
            "email":"the user's email"
        },
        "referrer":{
            "referralCode": "the referrer's referralCode saved on signup"
        },
        "refSource": "the refSource saved on signup"
    }
}
  • The apiToken  is availabe in the installation step of the campaign wizard.
  • firstname and lastname are optional
  • the referrer and the refSource can be omitted if not available(the user didn’t come from a referral)
  • The call can be safely run multiple times so no extra logic needed to track if this is the first action or not (no extra rewards will be given).

Request response:

{
  "referralCode": "rJdfjKY-b",
  "eventId": "evt_ZWE4NmUyMjQzOWRkN2ZjZWQ4ZDA"
}

The referralCode of the new participant will be returned along with the eventId of the transaction.

The referral dashboard

In a page available only to members (these are users that completed their action using the above call) you might want to show our 2 widgets so they can check their milestone progress and invite more friends.

  • copy our javascript snippet as is from the installation page of the wizard and place it before the closing body  tag.
  • add the 2 widget div  anywhere in the page you would like the widgets to appear
    <div data-vl-widget="embedForm"></div>
    <div data-vl-widget="milestoneWidget"></div> 
  • Identify the user on the frontend as well with some extra javascript (placed after the main snippet).
campaign.identify({
  email: "the user's email"
});
Did this answer your question?