Messaging - YerdySDK/yerdy-android GitHub Wiki
Messaging
Yerdy can be used to show users messages configured in the dashboard. See below for implementation details.
Placements
Using placements you can target different messages to different places inside your game. For example,
you could add a level_complete
placement and then setup a daily message rewarding the user for
completing a level to encourage users to complete a level daily.
Some examples placements could include launch
, game_over
, level_complete
, and achievement_unlocked
Note: Placements are optional. If you wish to show any message regardless of placement you can simply
pass in null
to most methods taking a placement.
Showing messages
To show a message, simply call showMessage(Activity activity, String placement)
, passing in a placement:
showMessage(Activity activity, String placement);
If you wish to check if a message is available before trying to show one, you can use isMessageAvailiable(String placement)
:
if(Yerdy.getInstance().isMessageAvailiable("launch"))
Yerdy.getInstance().showMessage(this, "launch");}
Delegate methods
You can implement the YerdyMessageDelegate
protocol to handle events related to messages (for example, pausing the game while a message is visible). For example, in our game's view controller, we could implement YerdyMessageDelegate
and do something like this:
protected void onCreate(Bundle savedInstanceState) {
...
Yerdy.getInstance().configureMessageDelegate(this);
...
}
@Override
public void willPresentMessageForPlacement(String placement) {
this.pauseGame();
}
@Override
public void didDismissMessageForPlacement(String placement) {
this.unpauseGame();
}
If you'd like to show any additional messages when the user cancels the previous one, you can return true
from the shouldShowAnotherMessageAfterUserCancelForPlacement(…)
method, like so:
@Override
public boolean shouldShowAnotherMessageAfterUserCancelForPlacement(String placement) {
return true;
}
Handling message triggered actions
The YerdyMessageDelegate
protocol contains methods some additional methods for handling actions triggered by messages.
Rewards
Messages may contain rewards for the user. For example, you could reward all players with some extra currency for playing on a certain day. To handle this inside the app, you need to implement the handleReward(YRDReward reward)
delegate method. For example:
@Override
public void handleReward(YRDReward reward) {
// 'rewards' is a dictionary contain reward names & amounts, like:
// { "bricks" : 5 }
// For example, if you have a class 'InventoryManager' used for tracking the user's inventory,
// you could do something like:
for(YRDRewardItem rewardItem : reward.getRewards())
{
if(rewardItem.getName().equals("Gold")) {
//handle "Gold" specially because it is a currency
CurrencyManager.addCurrency(rewardItem.getName(), rewardItem.getAmount());
} else {
//assume everything else is just in game items of some sort
InventoryManager.addItem(rewardItem.getName(), rewardItem.getAmount());
}
}
}
In App Purchases
In app purchases can be triggered via a message. For example, if you are running a sale on an IAP in your app, you can setup an action in the Yerdy dashboard to bring attention to it, and to start that IAP directly from the message. To support this, you need to implement the handleInAppPurchase(YRDInAppPurchase purchase)
delegate method. For example:
@Override
public void handleInAppPurchase(YRDInAppPurchase purchase) {
// 'purchase' contains a product identifier you can use to start an in-app purchase.
// For example, if you have a class 'InAppManager' used for handling in app purchases,
// you could do something like:
startInAppPurchase(purchase.getProductIdentifier());
}
Item Purchases
In addition to in app purchases, you can trigger in-game item purchases via messages. For example, you could setup an action in the Yerdy dashboard that prompts the user to purchase a newly released item. To support this, you need to implement the handleItemPurchase(YRDItemPurchase purchase)
delegate method. For example:
@Override
public void handleItemPurchase(YRDItemPurchase purchase) {
// 'purchase' contains a product identifier you can use to start an in-game item purchase
// For example, if you have a class 'StoreManager' used for purchasing in game items,
// you could do something like:
startItemPurchase(purchase.getItem());
}
Navigation Events
Messages can also trigger navigation events. For example, you can setup an action in the Yerdy dashboard that sends users to the store screen inside your game. To handle this, you'll need to implement the handleNavigation(String screen)
method. For example:
@Override
public void handleNavigation(String screen) {
if(screen.equals("store")) {
openStoreScreen();
} else {
//Handle Other Screens...
}
}