HomeAppVirality DocsAndroid SDK IntegrationPublic Methods

Public Methods

AppVirality provides a very simple and efficient approach for an application to communicate with our SDK.

A whole set of public methods exists within the SDK using which you can easily access most of the growth hacks data, execute various SDK tasks, invoke from a large set of APIs, etc.

AppVirality is the main SDK class and point of interface for an application to communicate with the SDK.
Most of the methods you will use will be from this class, so its very important to instantiate it before actually starting to use it. Though it can be instantiated from any class, but it is highly recommended to do so in the very first screen of your app, so that the SDK would be ready to use by the time your app transits to the main screen.

Use the following code to instantiate the AppVirality class:

 
 AppVirality appVirality = AppVirality.getInstance(this);
NOTE:
As AppVirality class uses singleton format, you can use the same above code to retrieve its instance throughout your app.

Below is a full list of public methods provided by the AppVirality SDK, you can check them out to know their use case, return type and input parameters:


 
 static AppVirality getInstance(Context context)
 
 static AppVirality getInstance(Context context, Config config)

Returns the AppVirality class singleton, instantiating it if not already instantiated.
Include this method in the very first screen of your app, so that the SDK would be ready to use by the time your app transits to the main screen.

Parameters

context
Context
The context to instantiate the class
config
Config
Config class instance to customize the configuration

Returns

AppVirality AppVirality class singleton

 


 
 void checkAttribution(CheckAttributionListener checkAttributionListener)

This callback is used to check the attribution status for a user, it returns the user and referrer data in the callback.
This method can be used to check if the user is an existing user, referred user, etc.

Parameters

checkAttributionListener
CheckAttributionListener
To get the user and referrer data in the callback after API execution.

  
  void init(UserDetails userDetails, AppViralitySessionInitListener appViralitySessionInitListener)

Initializes the SDK. Calls the initialization APIs to get the user and referrer data.

First create a UserDetails class instance and set the user data using its setter methods, then pass that instance in this method. Use this method in the very first screen of your app so that all required data would be ready by the time your app transits to the main/home screen.

Parameters

userDetails
UserDetails
Carrying the user data to be used for initialization.
appViralitySessionInitListener
AppViralitySessionInitListener
Callback interface if you want to get the callback after API execution ; else null.

  
void recordImpressionsClicks(String campaignId, boolean isImpression, boolean isClick)

Records impressions or clicks for a campaign.
For ex, if a user launches the Word of Mouth campaign its an impression, if he/she clicks on social network to refer its a click.

Parameters

campaignId
String
Campaign ID for which to record the impression or click.
isImpression
boolean
True, if recording an impression ; else False.
isClick
boolean
True, if recording a click ; else False.

  
  void submitReferralCode(String referralCode, SubmitReferralCodeListener submitReferralCodeListener)

Submits the referrer’s referral code to attribute a user.
Upon successful execution the user will be attributed to the referrer whose referral code is passed in this method. Use this method only if the attribution has not happened already from Referral Link.

Parameters

referralCode
String
Referral code of the referrer. It can contain characters from a-z, A-Z, 0-9, or – only.
submitReferralCodeListener
SubmitReferralCodeListener
Callback interface if you want to get the callback after API execution ; else NULL

  
  void updateAppUserInfo(UserDetails userDetails, UpdateUserInfoListener updateUserInfoListener)

This method is used to update various user related data like username, address, push token, etc.

First create a UserDetails class instance and set the user data you want to update using its setter methods, then pass that instance in this method.

Parameters

userDetails
UserDetails
Carrying the user data to be updated.
updateUserInfoListener
UpdateUserInfoListener
Callback interface if you want to get the callback after API execution ; else NULL

  
  void saveConversionEvent(String event, String transactionValue, String transactionUnit, JSONObject extraInfo, Constants.GrowthHackType growthHackType, ConversionEventListener conversionEventListener)

This method is used to record conversion events.

Standard conversion events include install, signup and transaction, apart from these you can also record any custom event for which you may want to reward the user. Recording conversion events are very critical for rewarding a user, reward for an event shall only be given after it gets recorded.

Parameters

event
String
Name of the event to be recorded.
transactionValue
String
Transaction amount for the event if applicable ; else null.
transactionUnit
String
Transaction unit for the event if applicable ; else null.
extraInfo
JSONObject
Additional data to be returned with the webhook.
growthHackType
enum
Type of growth hack for which recording event. Ex, Constants.GrowthHackType.Word_of_Mouth, Constants.GrowthHackType.Loyalty_Program, etc.
conversionEventListener
ConversionEventListener
Callback interface if you want to get the callback after API execution ; else NULL

  
  void getCampaignTerms(String campaignId, CampaignTermsListener campaignTermsListener)

Used to get the terms and conditions for a campaign.
It calls the /campaignterms API and passes back the fetched terms and conditions in the callback.

Parameters

campaignId
String
Campaign ID for which to fetch the terms and conditions.
campaignTermsListener
CampaignTermsListener
Callback interface to get the campaign's terms and conditions in the callback.

  
  void customizeReferralCode(String referralCode, CustomizeRefCodeListener customizeRefCodeListener)

Requests the /customizereferralcode API to customize the referral code for a user.
Use customizeRefCodeListener to know if the referral code got changed and update it in the campaign details in your app.

Parameters

referralCode
String
New Referral Code. It can contain characters from a-z, A-Z or 0-9 only, with a maximum length of 10 characters.
customizeRefCodeListener
CustomizeRefCodeListener
Callback interface to get the callback after API execution, and to know if the referral code got changed or not

  
  void getUserRewardDetail(String campaignId, UserBalanceListener userBalanceListener)

Used to get the reward data for a user.
It calls the /getuserbalance API to fetch the user balance and passes it back in the callback.

Parameters

campaignId
String
Campaign ID for which to get the reward data.
userBalanceListener
UserBalanceListener
Callback interface to get the reward data in the callback

  
  void getUserRewards(Constants.GrowthHackType growthHackType, String campaignId, UserRewardsListener userRewardsListener)

Used to get the detail reward data for a user.
It calls the /getuserrewards API to fetch the user reward detail and passes it back in the callback.

Parameters

growthHackType
enum
Type of growth hack for which getting the rewards data. Ex, Constants.GrowthHackType.Word_of_Mouth, Constants.GrowthHackType.Loyalty_Program, etc.
campaignId
String
Campaign ID for which to get the reward data.
userRewardsListener
UserRewardsListener
Callback interface to get the detail reward data in the callback

  
  void getUserCoupons(UserCouponsListener userCouponsListener)

This method is used to get the coupons for a user.
It calls the /getusercoupons API to fetch the user coupons data and passes it back in the callback.

Parameters

userCouponsListener
UserCouponsListener
Callback interface to get the user coupons data in the callback

  
  void getCouponPools(String campaignId, CouponPoolsListener couponPoolsListener)

This method is used to get the coupons pools from which the user could redeem coupons.
It calls the /getcouponpools API to fetch the coupon pools data and passes it back in the callback.

Parameters

campaignId
String
Campaign ID for which to get the coupon pools data. Required, if want to get the coupon pools data for some particular campaign ; else null to get all coupon pools data for an app
couponPoolsListener
CouponPoolsListener
Callback interface to get the coupon pools data in the callback

  
  void redeemFromPool(String poolId, CouponRedeemListener couponRedeemListener)

This method is used to redeem a coupon from some coupon pool.
It calls the /redeemrewards API to redeem the coupon.

Parameters

poolId
String
Coupon Pool ID from which to redeem the coupon.
couponRedeemListener
CouponRedeemListener
Callback interface if you want to get the callback after API execution ; else NULL

  
  void getFriends(int pageIndex, int pageSize, GetFriendsListener getFriendsListener)

This method is used to get the user’s friends.
It calls the /getfriendslist API to fetch the friends data and passes it back in the callback.

Parameters

pageIndex
int
Index of the page for implementing Paging.
pageSize
int
Number of records to fetch per page.
getFriendsListener
GetFriendsListener
Callback interface to get the friends data in the callback

  
  void recordProductAttribution(String clickId, ProductAttributionListener productAttributionListener)

This method is used to record the attribution for a shared product.
It calls the /recordproductattribution API to attribute share to the user who shared the product.

Parameters

clickId
String
Click ID from intent extras when someone clicks on the shared product deep link.
productAttributionListener
ProductAttributionListener
Callback interface to get the API response in the callback

  
  void getReferrerDetails(ReferrerDetailsReadyListener referrerDetailsReadyListener)

This method is used to get the referrer and user details from the SDK.
If the details are already available with the SDK it will pass them back in the callback ; else will be passed after SDK gets the details from some API response.

Parameters

referrerDetailsReadyListener
ReferrerDetailsReadyListener
Callback interface to get the referrer details in the callback

  
  void getCampaigns(Constants.GrowthHackType growthHackType, CampaignDetailsListener campaignDetailsListener)

This method is used to get the active campaign details.

If the details are already available with the SDK it will pass them back in the callback ; else will be passed after fetching from the server. When in Test Mode, each call to this method will invoke a call to “/getcampaign” API to refresh campaign details whereas in Live Mode it refreshes the campaign details if the details were last fetched more than half hour before.

Parameters

growthHackType
enum
Type of growth hack for which to get campaign details
Example: Constants.GrowthHackType.Word_of_Mouth, Constants.GrowthHackType.Loyalty_Program, etc.
Required, if you want to get campaign details for some particular growth hack type ; else NULL to get all active campaign details
campaignDetailsListener
CampaignDetailsListener
Callback interface to get the campaign details in the callback

  
  boolean checkUserTargeting(CampaignDetail campaignDetail, boolean isMiniNotification)

This method is used to check the user targeting conditions as set on dashboard.

Use this method to check if the user targeting conditions satisfy before showing popup or notification prompting user to launch growth hack.

Parameters

campaignDetail
CampaignDetail
Details of the campaign for which the launch popup or notification
isMiniNotification
boolean
True if you want to show mini notification ; else False for popup

Returns

boolean True, if the user targeting conditions satisfy ; else False

  
  void saveRemindLater(CampaignDetail campaignDetail)

It just records a click on Remind Later option from some popup to launch the growth hack.
It is particularly needed to meet the user targeting conditions, for ex. when to show the popup again if user chooses to remind later.

Parameters

campaignDetail
CampaignDetail
Details of the campaign for which the user chose to remind later

  
  boolean isReferredUser()

This method is used to know if the user is a referred user.
It would be a referred user if the user has installed the app by clicking on some other user’s referral link.

Returns

boolean True, if the user is a referred user ; else False

  
  boolean isExistingUser()

This method is used to know if the user is an existing user.
It would be an existing user if the user already existed before installing the app or if the app has just got updated.

Returns

boolean True, if the user is an existing user ; else False

  
  void setExistingUser()

This method is used to mark a user as an existing user.
Once you display welcome screen to the new user, mark that user as an existing user to avoid displaying welcome screen again and again.

 


  
  String getReferrerRefCode()

This method is used to get the referrer’s referral code.

Referrer is the user on whose referral the user has installed the app.
The referral code returned here shall be used to attribute the user to the referrer.

Returns

String Referral code of the referrer

  
  String getAttributionSetting()

This method is used to get the type of attribution that your apps uses.
This setting specifies how a new user shall be attributed to the referrer.

Returns

String Attribution setting for the app. Possible values are:
 0 if the user can be attributed only via referral link
 1 if attribution can happen via referral link or referral code
 2 if attribution shall happen only via referral code

  
  boolean isAttributionConfirmed()

This method is used to check if the user has been attributed successfully to the referrer.

Returns

boolean True, if the user has been confirmed ; else False

  
  void popUpShown(String campaignId)

Used to record whenever a popup or mini notification prompting to launch the growth hack is shown to the user.

It is basically used by the SDK to meet the user targeting requirements, for ex. how many times to show the the popup, when to show again, etc. Use this method after displaying any such popup or mini notification to ensure that user targeting conditions work properly.

Parameters

campaignId
String
ID of the campaign for which the popup or notification has been shown

  
  void copiedToClipboard()

Used to record an invite event when a user copies his share link to share from outside the app.


  
  void invokeInvite(SocialItem socialItem, boolean isRewardExists)

Used to record an invite event when a user invites someone to the growth hack campaign.

Parameters

socialItem
SocialItem
SocialItem class instance which is being used for the invite.
isRewardExists
boolean
True, if reward exists for the campaign ; else False.

  
  void logout()

Used to logout the current logged-in user.

When invoked this method clears SDK data from the device, so that it can be used by some other user to login and participate in the growth hack campaigns. Use this method if your app supports login/logout feature so that multiple users with different email ids can use the same device.

 


  
  static void setReferrerKey(Context context, String referrer)

This method is used to set the referrer information received in the INSTALL_REFERRER broadcast when a user will download the app from play store.

Parameters

context
Context
Details of the campaign for which the user is inviting.
referrer
String
Data received in referrer parameter in the INSTALL_REFERRER broadcast

  
  boolean hasProductSharingReward(String sku, String category, int price)

This method is used to check if reward exists on a product under product sharing campaign. Use this method to show/hide the product share option.

Parameters

sku
String
SKU of the product.
category
String
Category of the product.
price
int
Price of the product.

Returns

boolean True, if product has reward under product sharing campaign ; else False

  
  String getProductSharingRewardMsg(String sku, String category, int price)

This method is used to get a reward message under product sharing campaign to be shown to the user for sharing the product. It checks what reward exists for referrer and friend on a product and returns a dynamic reward message for the same.

Parameters

sku
String
SKU of the product.
category
String
Category of the product.
price
int
Price of the product.

Returns

String Reward message, if at least one of referrer and friend has reward on sharing the product; else NULL

  
  CampaignDetail getCampaignDetail(Constants.GrowthHackType growthHackType, ArrayList<CampaignDetail> campaignDetails)

This method is used to get campaign detail for a particular growth hack type from a list of campaign details.

Parameters

growthHackType
enum
Type of growth hack whose campaign detail you want to get from the list. Ex, Constants.GrowthHackType.Word_of_Mouth, Constants.GrowthHackType.Loyalty_Program, etc.
campaignDetails
ArrayList<CampaignDetail>
Array list of campaign details.

Returns

CampaignDetail Campaign Details for the requested growth hack type.

  
  void recordSocialAction(String socialActionId, Constants.GrowthHackType growthHackType, String shortCode, String shareMsg)

This method is used to record the social action used for referral.

Parameters

socialActionId
String
Identifier for the social action used for sharing.
growthHackType
enum
Type of growth hack for which sharing on social channel. Ex, Constants.GrowthHackType.Word_of_Mouth, Constants.GrowthHackType.Loyalty_Program, etc.
shortCode
String
User's short code.
shareMsg
String
Message to be shared on social channel.

  
  String getClickId(String referrer)

This method is used to get the click-Id from ‘referrer’ string.

Parameters

referrer
String
Referrer string.

Returns

String Click-Id.

  
  String getProductCode(String referrer)

This method is used to get the product code of the shared product.

Parameters

referrer
String
Referrer string.

Returns

String Product Code of the shared product.

  
  String getUserKey()

This method is used to get the current user’s user key.

Returns

String User Key for the current user.

  
  void setInstagramImagePath(String path)

This method is used to set the Instagram share image path.

Parameters

path
String
Instagram share image path.

  
  void setPinterestImagePath(String path)

This method is used to set the Pinterest share image path.

Parameters

path
String
Pinterest share image path.

  
  void setTwitterImagePath(String path)

This method is used to set the Twitter share image path.

Parameters

path
String
Twitter share image path.

  
  void getInstagramImagePath()

This method is used to get the Instagram share image path.


  
  void getPinterestImagePath()

This method is used to get the Pinterest share image path.


  
  void getTwitterImagePath()

This method is used to get the Twitter share image path.


  
  void invokeProductShare(SocialItem socialItem, boolean isRewardExists, ProductDetails productDetails, JSONObject replacementTokens)

Used to record a product sharing event when user shares a product.

Parameters

socialItem
SocialItem
SocialItem class instance which is being used for the invite.
isRewardExists
boolean
True, if reward exists for the campaign ; else False.
productDetails
ProductDetails
ProductDetails class instance for the product being shared.
replacementTokens
JSONObject
Replacement tokens to be used for share message.
Was this article helpful to you? Yes No