Skip to content

The AppVirality Web SDK for SaaS is now leaner & more effective. Like any SDK based solution, this one employs a lot of callbacks internally which help it to gather data points or info.

We shall explore & lay out the key elements that compose these callback.
We shall also discover what each of these callbacks intend to achieve.

The idea here is to simply help you as a developer understand the system, and enable you to adapt your integration to suit specific needs of your app. Below is the list of Callbacks defined inside the SDK for its interoperability:

AppVirality Initialization (Init)

Initialize the SDK


This callback is used while initializing the AppVirality Web SDK. This will be the first callback used before using any other callback except ‘getReferrerCode’ and ‘getReferrer’ callbacks.
Initializing the SDK is critical to loading of the referral campaign details & retrieving user relevant info to use forward in the subsequent activities.

The callback returns a bunch of details about the user, like:

  • User Key (most important among all other details)
  • Whether user has a Referrer
  • Is an Existing User or not
  • Referral campaign details to be presented on Widget etc.

Below code block is how it is implemented:

appvirality.init(appkey,
{
email: USER-EMAIL,
name: USER-NAME,
code: REFERRER-CODE,
country: USER-COUNTRY,
useraccountid: USER-ACCOUNTID,
profileimage: USER-PROFILEPICURL,
phone: USER-MOBILENUMBER,
stripecustomerid: USER-STRIPECUSTOMERID
}, function (err, data) {
});

Init - Input Parameters

ParameterTypeDescription
appkeyStringApp key provided by AppVirality > Dashboard > AppDetails
emailStringUser’s email address
name
(optional)
StringFirst Name of the user
required to personalize the referral messages
code
(optional)
StringReferrer’s Referral Code
If friend enters during registration
useraccountid
(optional)
StringID of the user in your App
helps to identify users on dashboard as you do in your app(must be unique for every user)
profileimage
(optional)
StringUser profile picture URL
required to personalize the referral messages
phone
(optional)
StringUser’s mobile number
cityStringUser’s city
state
(optional)
StringUser’s state
country
(optional)
StringUser’s country
stripecustomerid
(optional)
StringUser StripeID

Init - Output Parameters

ParameterTypeDescription
userkeyStringUnique id generated by AppVirality for each registered user
hasreferrerbooleanIt will be ‘true’ if the user has referrer
isexistinguserbooleanIt will be ‘true’ if the user already registered
shareurlStringUser share Link used to invite friends
saascampaignidStringReferral campaign id
referralcodeStringUser referral code used to invite friends
successboolean‘True’ if the API call is successful
messageStringAny message from server if required

Get Campaign Details

This callback is useful to retrieve the campaign details to display the referral widget. This callback requires SDK initialization.


appvirality.getCampaignData(function (err, data) {
});

Campaign Details contains the following information:

Campaign Data - Output Parameters

Parameters Explained

ParameterTypeDecription
appidStringIdentifier for the app added in AppVirality Dashboard
campaignidStringIdentifier for the campaign
campaignnameStringName of the campaign as set on the dashboard
offertitleStringURL-encoded Campaign Title as set on dashboard
offerdescriptionStringURL-encoded Campaign Description as set on dashboard
campaignbgcolorStringBackground color code for the campaign
campaignstartdateStringcampaign start date
widgetfontStringFont name to be used in Widget
lastmodifieddateStringLast date on which campaign has been modified
socialactionsArray<socialactions>List of social actions configured on dashboard for sharing
customdomainStringCustom Domain configured to be used in share link
rewardtypeStringit will be from 0 to 3. Where 0 - no rewards, 1- reward for only referrer,2- reward for only friend,3-both referrer and friend have rewards.
rewardrulesArray<rewardrules>List of reward rules configured on dashboard
successbooleanTrue- on API success
messageStringMessage from server if required.

socialactions Explained

ParameterTypeDecription
socialactionidStringIdentifier for the social channel
socialactionnameStringName of the social action
sharemessageStringURL-encoded share message as set on dashboard
sharetitleStringURL-encoded share title as set on dashboard
shareimageurlStringimage url to be shared on social channel
displayorderStringdisplay order for social action while displaying on widget
emailaccountconfiguredbooleanit will be true if the email account configured on Dashboard to process invites.

rewardrules Explained

ParameterTypeDecription
campaignidintIdentifier for the campaign
rewardusertypeStringReward user, either Referrer or Friend
eventnameStringName of the event on which reward will be processed.
rewardintReward Value
rewardunitStringReward Unit, like ’$ credit’ or ’% discount’
rewardfrequencyintNumber of times the reward can be given.
mintranvalueintMinimum Transaction Value required to process reward in case of transaction based reward rule.
maxrewardamountintMaximum reward amount that can be awarded for this event.

Record Social Action

This callback will record the user social actions and process the invitation emails if SMTP email account is configured in AppVirality Dashboard.


appvirality.recordSocialAction(mailBody.value, socialActionId, mailTo.value, mailSubject.value, function (err, data) {
if (!err) {
if (data['mailsent']) {
//successfully sent email
}
else {
//failed to send email
}
}
});

RecordSocialAction - Input Parameters

ParameterTypeDescription
MailBody/SharingMessageStringEmail body, if email is invite channel or Message shared by the user for all other invite channels
socialactionidStringidentifier for the social action, which will be available from campaign details
mailto
(optional)
Stringcomma separated To-eamil id’s if the invite channel is email
mailsubject
(optional)
Stringmail subject if the invite channel is email

RecordSocialAction - Output Parameters

ParameterTypeDescription
mailsentbooleanTrue - if the email sent successfully

Get Terms

This callback is used to get the campaign’s terms and conditions as set on the dashboard.


appvirality.getTerms(function (err, data) {
});

Get Terms - Output Parameters

Parameters Explained

ParameterTypeDecription
successbooleanTrue, if API call was successful else False
messageStringCampaign’s Terms and Conditions

Get User Balance

This callback is used to retrieve the user balance.


appvirality.getUserBalance(function (err, data) {
});

Get User Balance - Output Parameters

Parameters Explained

ParameterTypeDecription
userbalanceArray<userbalance>Array of user balance details
successbooleanTrue, if API call was successful else False
messageStringMessage from the server, if required

userbalance Explained

ParameterTypeDecription
rewardunitStringReward amount unit
totalintTotal reward amount earned
claimedintReward amount claimed
pendingintReward amount pending

Get Friends List

This callback is used to retrieve the list of friends for the logged-in user.


appvirality.getFriendsList(function (err, data) {
});

Get Friends List - Output Parameters

Parameters Explained

ParameterTypeDecription
userbalanceArray<userbalance>Array of user balance details
friendsArray<friends>Array of friends
invitedfriendsArray<invitedfriends>Array of friends invited by the user
totalfriendsintArray of user balance details
convertedfriendsintArray of user balance details
successbooleanTrue, if API call was successful else False
messageStringMessage from the server, if required

userbalance Explained

ParameterTypeDecription
rewardunitStringReward Unit for the balance
totalintTotal reward amount earned
claimedintReward amount claimed
pendingintReward amount pending

friends Explained

ParameterTypeDecription
userkeyStringFriend’s unique identifier
useraccountidStringFriend’s account identifier
emailStringFriend’s email address
statusStringFriend’s current status with the app, ex SignUp, Converted, etc.
nameStringName of the Friend
profileimageStringFriend’s profile image URL
regdateStringFriend’s registration date
earnedrewardsArray<earnedrewards>Reward amount pending
isremindbooleanTrue, if user can remind his friend else False

earnedrewards Explained

ParameterTypeDecription
eventnameStringReward event name
rewardStringAmount of reward
rewardunitStringUnit of the reward
rewardedonStringDate on which rewarded
rewardstatusStringStatus of the reward, i.e. Approved, Rewarded, etc
rewardtypeStringReward Type, i.e. Coupon, InstoreCredit, etc
usertypeStringUser type, i.e. Referrer or Friend
couponStringRewarded coupon’s code
campaignidStringIdentifier of the campaign for which rewarded
campaignnameStringName of the campaign for which rewarded
growthhackStringName of the growth hack for which rewarded
couponimageStringCoupon’s Image URL
coupondetailsStringCoupon description
couponnameStringName of the coupon pool
friendemailStringFriend’s email address
friendnameStringFriend’s name
friendprofileimageStringFriend’s profile image URL

invitedfriends Explained

ParameterTypeDecription
friendemailStringFriend’s email address
regdateStringFriend’s registration date
isremindbooleanTrue, if user can remind his friend else False

Get Code

This callback is used to retrieve the referrer’s referral code.


appvirality.getReferrerCode(appkey, function (err, data) {
});

Get Code - Output Parameters

Parameters Explained

ParameterTypeDecription
referrercodeStringReferrer’s Referral Code

Validate Code

This callback is used to validate a referral code for a user, to know if it is valid or not.


appvirality.validateCode(referralCode, function (err, data) {
});

Validate Code - Input Parameters

ParameterTypeDescription
referralCodeStringReferrer’s referral code

Validate Code - Output Parameters

ParameterTypeDescription
successbooleanTrue, if the referral code is valid else False
messageStringMessage from the server, if required

Apply Code

This callback is used to apply referral code for a user, to confirm the referrer.


appvirality.applyCode(referralCode, function (err, data) {
});

Apply Code - Input Parameters

ParameterTypeDescription
referralCodeStringReferrer’s referral code

Apply Code - Output Parameters

ParameterTypeDescription
successbooleanTrue, if the referral code applied successfully else False
messageStringMessage from the server, if required

Get Referrer

This callback is used to retrieve the referrer details.


appvirality.getReferrer(appkey, referrercode, useremail, useraccountid, function (err, data) {
});

Get Referrer - Input Parameters

ParameterTypeDescription
appkeyStringApp key provided by AppVirality > Dashboard > AppDetails
referrercode
(optional)
StringInvite code used by the user during signup/subscription
useremail
(optional)
StringEmail of the current user for whom you want to get the referrer details
useraccountid
(optional)
StringID of the user in your App
helps to identify users on dashboard as you do in your app(must be unique for every user)

Get Referrer - Output Parameters

ParameterTypeDescription
referrercodeStringReferrer code of the user
referrernameStringReferrer name
profileimageStringProfile image url of the referrer
friendrewardStringCurrent on boarding user reward
friendrewardunitStringunit of the friend reward, like $ or %
friendrewardfrequencyStringreward duration, i.e. 3 months or 6 months
hasreferrerboolean‘True’ if the user has referrer when you invoke the call with user email
isexistinguserboolean‘True’ if the user already registered when you invoke the call with user email
userkeyStringUnique id generated by AppVirality for each registered user
successboolean‘True’ if the API success
messageStringAny message from server if required

Show Widget

This callback is used to display the Referral Widget to be used for referring a friend.


appvirality.widget(
{
title: 'Demo App',
description: 'AppVirality Demo app!',
iframe: true
}
);