Skip to main content

Build Your Own UI for Loyalty

tip

The callbacks of this section can be used to receive Loyalty User Profile Updates through the wappier Optimization SDK. The response data will be used to develop the Loyalty User Profile and/or to cross-promote these loyalty-related updates in your application.

Loyalty Unlocked Reward Update

By engaging with the application a user unlocks rewards. You can register a listener to receive updates for the unlocked rewards:

RewardUnlockListener rewardUnlockListener = (eventName, redeemableList) -> {
...
};

Wappier.getInstance().setRewardUnlockedListener(rewardUnlockListener);

Loyalty Points Update

You can register a listener to receive the loyalty points which the end user won, along with the respective event name that triggered this change:

NotificationBalanceListener notificationBalanceListener = (eventName, redeemableList) -> {
...
};

Wappier.getInstance().setBalanceIncreasedListener(notificationBalanceListener);

Loyalty Inventory Update

You can receive the end-user redeemed items by calling the method below:

This callback should be added occasionally based on when the client needs to be informed about the end-user's inventory. Ιndicatively it may be called when a new session starts and ends in your application.

Also, you can find relative information such as the title, description, and images of rewarded items along with the current state of the rewards.

Wappier.getInstance().getInventoryRequest(invTypes, invItemStatuses, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});

Arguments invTypes and itemStatuses are arrays of integers that can contain the following values:

ValueinvTypes Definition
0Items of type Loyalty
1Items of type Pricing
2Items of Type Campaign
ValueinvStatuses Definition
0All items
1Unlocked items
2Redeemed items

You can pass in each parameter a combination of more than one of the above values.

Response example:

{
"inventories": [
{
"type": 0, // INVENTORY_TYPE
"balance": {
"WP_POINTS": { // Loyalty Points
"total": 20000, // Total Loyalty Points
"current": 12200 // Current Loyalty Points
}
},
"redeemed": [ // Redeemed In-app Rewards

{
"amount": 2, // Reward Amount
"redeemable": {
"sku": "WP_20_COINS", // wappier Redeemable Identifier
"type": "INAPP", // redeemable type - "INAPP" for in-app rewards
"amount": 10, // redeemable amount
"refCode": "com.package.coin" //publisher's in-app reward identifier
}// The redeemed reward is 20 coins because the end-user got 2 WP_20_COINS. The WP_20_COINS redeemable is 10 com.package.coin
},...
],
"unlocked": [ // Unlocked In-app Rewards
{
"amount": 2, // Reward Amount
"redeemable": {
"sku": "WP_1_GEM", // wappier Redeemable Identifier
"type": "INAPP", // redeemable type - "INAPP" for in-app rewards
"amount": 1, // redeemable amount
"refCode": "com.package.gem" // publisher's in-app reward identifier
}// The unlocked reward is 2 gems because the end-user got 2 WP_1_GEM. The WP_1_GEM redeemable is 1 com.package.gem
},...
]
}
],
"total": 1 // number of user inventory
}

As you can see, the response describes three parts of current user state. The balance of user in points, the already unlocked rewards and the redeemed rewards.

Get Loyalty Notifications Count

You can get the current number of notifications on demand by using this method:

int notificationsCount = Wappier.getInstance().getNotificationsCount();

Get Loyalty Response

You may get the current Loyalty status and implement your Loyalty User Profile/ Loyalty Card. You can use the following method to fetch the Loyalty status:

Wappier.getInstance().getLoyaltyDetails(assetLevel, card, level, flatBuffer, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});

where the parameters indicate the data to be queried as follows:

ParameterValid ValuesValue Definition
assetLevel0/1/2no assets/only infoView/all assets
card0/1/2no card layout/card layout
level0/1/2only offers/offers & rewardGroups/offers & rewardGroups & rewards
flatBuffertrue/falseflat buffer/JSON response format

Alternatively, to fetch Loyalty’s data with the default values (assetLevel=2, card=0, level=2) you can use this method:

Wappier.getInstance().getLoyaltyDetails(flatBuffer, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});

Get Loyalty Tactic Reward

The following method is used in the Scratch & Win tactic and any lottery kind of tactic.

By calling this method, the wappier system will inform you about the reward that must be given to the user, based on the respective configuration.

Wappier.getInstance().getOfferReward("id", flatbuffer, (StringListener) response -> {
...
});

You can also pass FBS_JSON enum case to receive a response in flatbuffer format.

Update Loyalty Tactic Status

After giving the reward of the Scratch & Win tactic to the user, you can call the following method to inform us that the current status of the tactic is completed.

    Wappier.getInstance().statusUpdateRequest(OfferId, status);
StatusReason
activeYou will set the tactic as active (not supported yet)
inactiveYou will set the tactic as inactive (not supported yet)
pendingYou will set the tactic as pending (not supported yet)
completedYou will set the tactic as completed

Clear Notification On Tactic

You can clear the notification mark on every tactic that the user has already visited by passing the offer's id.

As a callback value you will get the current notification count.

Wappier.getInstance().clearNotification(OfferId, notification ->{});

Get Loyalty Theme

In order for a Loyalty card to be displayed you need to get the Loyalty theme of your app. You can do that by using the following method:

Wappier.getInstance().getLoyaltyTheme(flatBuffer, new StringResponseListener() {
@Override
public void onSuccess(String response) {
...
}

@Override
public void onError(String response) {
...
}
});

Set flatbuffer to true to receive the response in flatbuffer format or false for JSON format.

Getting User Status

You can get the end-user status for each Wappier service. In the response, you can find if the end user is included in the control or target group, for the Wappier service that you are asking for.

To get User Status, add the following code:

// tags is a List<String> and can take values "all" | "loyalty" | "pricing" | "campaign"
List<String> tags = new ArrayList<>();
tags.add("loyalty");
tags.add("pricing");
tags.add("campaign");

Wappier.getInstance().getUserStatus(tags, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});

which takes a list of tags as an argument and returns a JSON response as a String.

ArgumentService
loyaltyYou will get the status of the user for the Loyalty and Retention service
pricingYou will get the status of the user for the Pricing service
campaignYou will get the status of the user for the Personalized Interstitials service
allYou will get the status of the user for all Wappier services

Example Response:

"{
\"loyalty\" : {
\"population\" : 0.67220987,
\"control\" : false,
\"enabled\" : false
},
\"campaign\" : {
\"population\" : 0.36149076,
\"control\" : false,
\"enabled\" : false
},
\"pricing\" : {
\"population\" : 0.34617529,
\"control\" : false,
\"enabled\" : true,
\"billingCountry\": \"GR\",
\"isInScope\": true
}
}"

In the response, you may find if the user is included in the control or target group per each service.

  • If the end-user is included in the control group for the requested service if the {{service}}.control:true and {{service}}.enabled:false
  • If the end-user is included in the target group for the requested service if the {{service}}.control:false and {{service}}.enabled:true

Loyalty Status Update Notification

By registering the listener below, you can receive the updates on the user’s current loyalty status:

LoyaltyListener loyaltyListener = new LoyaltyListener() {
@Override
public void onLoyaltyStatusChanged(boolean enabled) {
...
}
};

Wappier.getInstance().setLoyaltyListener(loyaltyListener);

Loyalty Notifications Count Update

By registering the listener below, you can receive the updates on the user’s current notifications count. For instance, you can show their count notifications on your custom button by adding the following lines:

[WappierSDK addNotificationCountListener:^(int count){ ... }];
NotificationListener notificationListener = new NotificationListener() {
@Override
public void onNotificationsChanged(int notifications) {
...
}
};

Wappier.getInstance().setNotificationListener(notificationListener);

In-App Products Setup & Redemption Flow

Once the end-user is able to claim a Loyalty reward, you have to call the following method by passing the appropriate rewardId. This request opens a transaction in our backend service for the current reward and it will be marked as in progress.

As a response, you will get information about the current reward like SKU, amount, redemption id, etc.

You have to iterate this String and filter the redemptionId that you have to pass in completeRewardRedemption later on.

Wappier.getInstance().startRewardRedemption(rewardId, flatBuffer, new RedemptionStartFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});

Afterwards, you have to inform the wappier service that you have already given the reward to the user.

Please keep in mind that the redemption is alive for 30 seconds, so you have to complete the transaction in time.

In the following code we demonstrate, how to complete a transaction.

Wappier.getInstance().completeRewardRedemption(true, redemptionId, flatBuffer, new RedemptionCompleteFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});

You can cancel a redemption if the reward is not given to the end-user by calling the following:

Wappier.getInstance().completeRewardRedemption(false, redemptionId, flatBuffer, new RedemptionCompleteFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});

You can pass JSON to receive the response in json format or FBS_JSON enum case to receive the response in flatbuffer JSON format.