Callbacks

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:

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
Init - Output Parameters

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

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
RecordSocialAction - Output Parameters

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

This callback is used to retrieve the user balance.



 appvirality.getUserBalance(function (err, data) {
    
 });
Get User Balance - Output Parameters

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

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



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

});
Get Code - Output Parameters

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
Validate Code - Output Parameters

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
Apply Code - Output Parameters

This callback is used to retrieve the referrer details.



 appvirality.getReferrer(appkey, referrercode, useremail, useraccountid, function (err, data) {
 
 });
Get Referrer - Input Parameters
Get Referrer - Output Parameters

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
    }
);

 

Was this article helpful to you? Yes No