Build Your Own UI for Loyalty
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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
RewardUnlockListener rewardUnlockListener = (eventName, redeemableList) -> {
...
};
Wappier.getInstance().setRewardUnlockedListener(rewardUnlockListener);
[WappierSDK addRewardUnlockedListener:^(NSString *event, NSArray<WappierRedeemedReward *> *redeemables) {
...
}];
Wappier.Instance.setRewardUnlockDelegate((eventName, redeemableItems) =>
{
...
});
WappierSDKWrapper::getInstance()->setNotificationRewardUnlockedListener(
[](const char* eventName,std::vector<WPRedeemableItem*> &redemptionList) {
....
});
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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
NotificationBalanceListener notificationBalanceListener = (eventName, redeemableList) -> {
...
};
Wappier.getInstance().setBalanceIncreasedListener(notificationBalanceListener);
[WappierSDK addBalanceIncreasedListener:^(NSString *event, NSArray<WappierRedeemedReward *> *redeemables) {
...
}];
Wappier.Instance.setBalanceIncreaseDelegate((eventName, redeemableItems) =>
{
...
});
WappierSDKWrapper::getInstance()->setNotificationBalanceIncreasedListener(
[](const char* eventName,std::vector<WPRedeemableItem*> &redemptionList) {
....
});
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.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
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:
Value | invTypes Definition |
---|---|
0 | Items of type Loyalty |
1 | Items of type Pricing |
2 | Items of Type Campaign |
Value | invStatuses Definition |
---|---|
0 | All items |
1 | Unlocked items |
2 | Redeemed items |
You can pass in each parameter a combination of more than one of the above values.
NSArray *inventoryTypes = @[@(0), @(1)];
NSArray *itemsStatuses = @[@(0), @(1), @(2)];
[WappierSDK queryInventoryWithTypes:inventoryTypes andStatuses:itemsStatuses];
The inventoryTypes
parameter could be an array of:
typedef NS_ENUM(NSInteger, XNDInventoryType) {
XNDInventoryTypeLoyalty=0, // Inventory with Loyalty Program items
XNDInventoryTypePricing, // Inventory with Pricing Program items
XNDInventoryTypeCampaign // Inventory with Ad Campaing Program items
};
The itemsStatuses
parameter could be an array of:
typedef NS_ENUM(NSInteger, XNDItemStatus) {
XNDItemStatusAll=0,
XNDItemStatusUnlocked,
XNDItemStatusRedeemed
};
You can have a mix of values for each parameter:
inventoryTypes = @[@(0), @(2)]
If you pass wrong parameters in the callback, you will not be informed and the response listener will never be called.
You can add an inventory update listener that returns the user inventory:
[WappierSDK addInventoryListener:^(NSArray<XNDInventory *> *inventory) {
...
}];
int[] invTypes = { 0 };
int[] statuses = { 0, 1 };
Wappier.Instance.getInventoryRequest(invTypes, statuses, (inventoryItems) =>
{
...
});
Arguments invTypes
and itemStatuses
are arrays of integers that can contain the following values:
Value | invTypes Definition |
---|---|
0 | Items of type Loyalty |
1 | Items of type Pricing |
2 | Items of Type Campaign |
Value | invStatuses Definition |
---|---|
0 | All items |
1 | Unlocked items |
2 | Redeemed items |
You can pass in each parameter a combination of more than one of the above values.
If you pass wrong params in the callback, you will not be informed and the response listener will never be called.
std::set<int> invType;
invType.insert(0);
std::set<int> invStatuses;
invStatuses.insert(0);
WappierSDKWrapper::getInstance()->getInventory(invType,invStatuses,[](const char* response){
....
});
The invTypes
parameter could be
enum INVENTORY_TYPE {
LOYALTY = 0 , // Inventory with Loyalty Program items
PRICING = 1 , // Inventory with Pricing Program items
CAMPAIGN = 2 // Inventory with Ad Campaing Program items
}
The invItemStatuses
parameter could be:
enum ITEM_STATUS {
ALL = 0 ,
UNLOCKED = 1 ,
REDEEMED = 2
}
You can have a mix of values for each parameter:
inventoryTypes = @[@(0), @(2)]
If you pass wrong parameters in the callback, you will not be informed and the response listener will never be called.
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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
int notificationsCount = Wappier.getInstance().getNotificationsCount();
NSInteger notificationsCount =[WappierSDK getNotificationsCount];
int count = Wappier.Instance.getNotificationsCount();
int notificationsCount = WappierSDKWrapper::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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().getLoyaltyDetails(assetLevel, card, level, flatBuffer, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});
[WappierSDK getLoyaltyDetailsWithAssetLevel:assetLevel
card:card
level:level
flatbuffer:flatbuffer
callback: ^(NSDictionary *response, NSError *error) {
// ...
}];
Wappier.Instance.getLoyaltyDetails(assetLevel, card, level, WPResponseFormat.JSON, (response, error) => {
...
});
WappierSDKWrapper::getInstance()->getLoyaltyDetails(assetLevel, card, level, JSON, [](const char* response){
...
});
where the parameters indicate the data to be queried as follows:
Parameter | Valid Values | Value Definition |
---|---|---|
assetLevel | 0/1/2 | no assets/only infoView/all assets |
card | 0/1/2 | no card layout/card layout |
level | 0/1/2 | only offers/offers & rewardGroups/offers & rewardGroups & rewards |
flatBuffer | true/false | flat 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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().getLoyaltyDetails(flatBuffer, new StringListener() {
@Override
public void onSuccess(String response) {
...
}
});
[WappierSDK getLoyaltyDetails:flatBuffer callback:^(NSDictionary *dictionary, NSError *error) {
...
}];
Wappier.Instance.getLoyaltyDetails(WPResponseFormat.JSON, (response, error) => {
...
});
WappierSDKWrapper::getInstance()->getLoyaltyDetails(JSON, [](const char* 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.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().getOfferReward("id", flatbuffer, (StringListener) response -> {
...
});
[WappierSDK getOfferRewardWithId:(@"id") flatbuffer:flatbuffer callback:^(NSDictionary * dictionary) {
...
}];
Wappier.Instance.getOfferReward(id, WPResponseFormat.JSON, response =>
{
...
});
WappierSDKWrapper::getInstance()->getOfferReward(offerId, JSON, [](const char* 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
.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().statusUpdateRequest(OfferId, status);
[WappierSDK updateOfferStatusWithOfferId:OfferId status:Status];
Wappier.Instance.updateOfferStatus(id, status);
WappierSDKWrapper::getInstance()->updateOfferStatus(OfferId,Status);
Status | Reason |
---|---|
active | You will set the tactic as active (not supported yet) |
inactive | You will set the tactic as inactive (not supported yet) |
pending | You will set the tactic as pending (not supported yet) |
completed | You 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.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().clearNotification(OfferId, notification ->{});
[WappierSDK clearNotificationsForOfferId:offerId callback:^(int totalNotifications) {
...
}];
Wappier.Instance.clearNotification(id, count =>
{
...
});
WappierSDKWrapper::getInstance()->clearNotification(id, [](int notificationCount){
...
});
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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
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.
[WappierSDK getLoyaltyTheme:flatbuffer callback:^(NSDictionary *dictionary, NSError *error) {
...
}];
Wappier.Instance.getLoyaltyTheme(WPResponseFormat.JSON, (response,error) => {
...
});
You can pass FBS_JSON
enum case to receive a response in flatbuffer format or JSON
for JSON format.
WappierSDKWrapper::getInstance()->getLoyaltyTheme(JSON, [](const char *response, const char *error) {
...
});
You can also pass FBS_JSON
enum case to receive a response in flatbuffer 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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
// 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) {
...
}
});
// tags is an Array<NSString> and can take values "all" | "loyalty" | "pricing" | "campaign"
NSArray *tags = @[
@"loyalty",
@"pricing",
@"campaging"
];
[WappierSDK getUserStatus:tags callback:^(NSDictionary * response) {
...
}];
// tags is a string[] and can take values "all" | "loyalty" | "pricing" | "campaign"
string[] tags = new string[] {"loyalty","pricing","campaign"}
Wappier.Instance.GetUserStatus(tags, UserStatusCallback);
void UserStatusCallback(string response)
{
//Handle response json
}
OR
Wappier.Instance.GetUserStatus(tags, response => {
//Handle response json
});
// tags is a std::vector<const char*> and can take values "all" | "loyalty" | "pricing" | "campaign"
std::vector<const char*> tags = {"loyalty","pricing","campaign"};
WappierSDKWrapper::getInstance()->getUserStatus(tags, [](const char* response) {
...
});
which takes a list of tags as an argument and returns a JSON response as a String.
Argument | Service |
---|---|
loyalty | You will get the status of the user for the Loyalty and Retention service |
pricing | You will get the status of the user for the Pricing service |
campaign | You will get the status of the user for the Personalized Interstitials service |
all | You 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:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
LoyaltyListener loyaltyListener = new LoyaltyListener() {
@Override
public void onLoyaltyStatusChanged(boolean enabled) {
...
}
};
Wappier.getInstance().setLoyaltyListener(loyaltyListener);
[WappierSDK addLoyaltyStatusListener:^(BOOL status){
...
}];
Wappier.Instance.setLoyaltyStatusDelegate(flag =>
{
...
});
WappierSDKWrapper::getInstance()->setLoyaltyListener([](bool enabled){
if(enabled)
//do something if Loyalty is enabled
});
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){ ... }];
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
NotificationListener notificationListener = new NotificationListener() {
@Override
public void onNotificationsChanged(int notifications) {
...
}
};
Wappier.getInstance().setNotificationListener(notificationListener);
[WappierSDK addNotificationCountListener:^(int count){
...
}];
Wappier.Instance.setLoyaltyNotificationsCountDelegate(count =>
//do something with the count of loyalty notifications
//e.g. show some icon over the loyalty icon
});
WappierSDKWrapper::getInstance()->setNotificationListener([](int count) {
//do something with the count of loyalty notifications
//e.g. show some icon over the loyalty icon
});
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.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().startRewardRedemption(rewardId, flatBuffer, new RedemptionStartFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});
[WappierSDK startRewardRedemptionWithId:@"redemptionId" flatbuffer:flatbuffer completion:^(NSDictionary *dictionary, NSError *error) {
...
}];
Wappier.Instance.startRewardRedemption(rewardId, WPResponseFormat.JSON, (response, error) =>{
...
});
WappierSDKWrapper::getInstance()->startRewardRedemption(rewardId, JSON,[](const char *response,const char *error) {
...
});
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.
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().completeRewardRedemption(true, redemptionId, flatBuffer, new RedemptionCompleteFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});
[WappierSDK completeRewardRedemptionWithId:@"redemptionId" result:YES flatbuffer:flatbuffer completion:^(NSDictionary *dictionary, NSError *error) {
...
}];
Wappier.Instance.completeRewardRedemption(true, redemptionId, WPResponseFormat.JSON, (response, error) => {
...
});
WappierSDKWrapper::getInstance()->completeRewardRedemption(redemptionId, true, JSON, [](const char *response,const char *error) {
...
});
You can cancel a redemption if the reward is not given to the end-user by calling the following:
- Android(Java)
- iOS(obj-C)
- Unity(C#)
- C++
Wappier.getInstance().completeRewardRedemption(false, redemptionId, flatBuffer, new RedemptionCompleteFlowListener() {
@Override
public void onSuccess(String response) {
...
}
@Override
public void onError(String errorReason) {
...
}
});
[WappierSDK completeRewardRedemptionWithId:@"redemptionId" result:NO flatbuffer:flatbuffer completion:^(NSDictionary *dictionary, NSError *error) {
...
}];
Wappier.Instance.completeRewardRedemption(false, redemptionId, WPResponseFormat.JSON, (response, error) => {
...
});
WappierSDKWrapper::getInstance()->completeRewardRedemption(redemptionId, false, JSON, [](const char *response,const char *error) {
...
});
You can pass JSON
to receive the response in json format or FBS_JSON
enum case to receive the response in flatbuffer JSON format.