Tapjoy managed currency enables you to use Tapjoy’s servers to store your user’s currency amount. This is a free service provided by Tapjoy for all developers that integrate Tapjoy’s publisher SDKs. This eliminates the back-end work normally needed to store your user’s currency data for your application. Integration is relatively simple and integration instructions are detailed below.
To get the current virtual currency of a user, call the following method:
VIRTUAL CURRENCY BEST PRACTICE: We recommend calling getCurrencyBalance as often as possible so the user’s balance is always up-to-date. Common places to check the user’s balance are when the app launches, when the app resumes, when Tapjoy views close, and when placement content disappears. It is often particularly useful to call getCurrencyBalance (or the equivalent call on whatever platform you are using) 3.5 seconds after advertising content disappears. This gives the reward time to get through our system by the time you check for the currency balance. If you check getCurrencyBalance immediately after the content is finished displaying, the reward might not have time to appear in the user’s balance before the balance is queried.
NOTE: It’s important to note that while Tapjoy does its best to reward users as quickly as possibly we can’t guarantee that the user will be rewarded instantaneously. There are a lot of factors that determine how long it may take to reward a user. As a best practice, in addition to checking when the video ad closes you should check for an updated balance at regular intervals and after certain app events like app launch, app resume, in between levels, before your store loads, etc. We also recommend that you let your users know that it may take some time before an offer gets completed.
// This method requests the tapjoy server for current virtual currency of the user.
//Get currency
[Tapjoy getCurrencyBalanceWithCompletion:^(NSDictionary *parameters, NSError *error) {
if (error) {
//Show error message
NSLog(@"getCurrencyBalance error: %@", [error localizedDescription]);
} else {
//Update currency value of your app
NSLog(@"getCurrencyBalance returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]);
}
}];
As described above, you will be notified about the currency balance in the completion block, with the parameter “currencyName” providing the name of the currency and “amount” providing the user’s balance.
For implementation details, refer to the sample application in the SDK package.
Tapjoy.getCurrencyBalance(new TJGetCurrencyBalanceListener(){
@Override
public void onGetCurrencyBalanceResponse(String currencyName, int balance) {
Log.i(TAG, "getCurrencyBalance returned " + currencyName + ":" + balance);
}
@Override
public void onGetCurrencyBalanceResponseFailure(String error) {
Log.i("Tapjoy", "getCurrencyBalance error: " + error);
}
});
You will be notified with the currency balance in the onGetCurrencyBalanceResponse(String currencyName, int balance) callback method in the TJGetCurrencyBalanceListener you specified. You will be notified of an error condition in the onGetCurrencyBalanceResponseFailure(String error) callback method.
NOTE: It is best to call getCurrencyBalance(…) on application startup and resume. The callback notifiers for SPEND and AWARD currency also return the total virtual currency balance of the user, so use these to update the total amount of currency the user has.
// Get currency
Tapjoy.GetCurrencyBalance();
// on enable, add delegates
void OnEnable() {
Tapjoy.OnGetCurrencyBalanceResponse += HandleGetCurrencyBalanceResponse;
Tapjoy.OnGetCurrencyBalanceResponseFailure += HandleGetCurrencyBalanceResponseFailure;
}
// on disable, remove delegates
void OnDisable() {
Tapjoy.OnGetCurrencyBalanceResponse -= HandleGetCurrencyBalanceResponse;
Tapjoy.OnGetCurrencyBalanceResponseFailure -= HandleGetCurrencyBalanceResponseFailure;
}
public void HandleGetCurrencyBalanceResponse(string currencyName, int balance) {
Debug.Log("C#: HandleGetCurrencyBalanceResponse: currencyName: " + currencyName + ", balance: " + balance);
}
public void HandleGetCurrencyBalanceResponseFailure(string error) {
Debug.Log("C#: HandleGetCurrencyBalanceResponseFailure: " + error);
}
You will be notified about the currency balance in the OnGetCurrencyBalanceResponse handler you specified, which will pass currencyName and balance parameters. You will be notified of an error in the OnGetCurrencyBalanceResponseFailure handler.
try {
let result = await Tapjoy.getCurrencyBalance();
let currencyName = result['currencyName'];
let amount = result['amount'];
} catch (error: any) {
//Handle error
}
We use a promise in React Native for getCurrencyBalance()
which takes no parameters. The promise resolves with a dictionary or an error (which should be caught). The dictionary key currencyName
holds a String with the currency amount.
// Get currency
TapjoyAIR.getCurrencyBalance();
// Setup handlers
TapjoyAIR.addEventListener(TJCurrencyEvent.GET_CURRENCY_BALANCE_SUCCESS, tapjoyCurrencyEventHandler);
TapjoyAIR.addEventListener(TJCurrencyEvent.GET_CURRENCY_BALANCE_FAILURE, tapjoyCurrencyEventHandler);
private function tapjoyCurrencyEvents(event:TJCurrencyEvent):void {
trace("Tapjoy sample event listener for " + event.type + ", " + event.balance + ", " + event.currencyName);
}
You will be notified about the currency balance in the TJCurrencyEvent.GET_CURRENCY_BALANCE_SUCCESS handler you specified, which will pass a TJCurrencyEvent object. This object contains currencyName and balance properties. You will be notified of an error in the TJCurrencyEvent.GET_CURRENCY_BALANCE_FAILURE handler.
In order to notify users that they’ve earned virtual currency since the last time the last time the app queried the user’s currency balance, set a notification observer:
// Set the notification observer for earned-currency-notification. It's recommended that this be placed within the applicationDidBecomeActive method.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEarnedCurrencyAlert:) name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];
// In the following method, you can set a custom message or use the default UIAlert to inform the user that they just earned some currency.
- (void)showEarnedCurrencyAlert:(NSNotification*)notifyObj
{
NSNumber *currencyEarned = notifyObj.object;
int earnedNum = [currencyEarned intValue];
NSLog(@"Currency earned: %d", earnedNum);
// Pops up a UIAlert notifying the user that they have successfully earned some currency.
// This is the default alert, so you may place a custom alert here if you choose to do so.
[Tapjoy showDefaultEarnedCurrencyAlert];
// This is a good place to remove this notification since it is undesirable to have a pop-up alert more than once per app run.
[[NSNotificationCenter defaultCenter] removeObserver:self name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];
}
To be notified whenever the user earns virtual currency (eg. through Offers), set up your earned currency listener with the following method:
// Get notifications whenever Tapjoy currency is earned.
Tapjoy.setEarnedCurrencyListener(new TJEarnedCurrencyListener() {
@Override
public void onEarnedCurrency(String currencyName, int amount) {
Log.i("Tapjoy", "You've just earned " + amount + " " + currencyName);
}
});
You will be notified with the currency earned in the onEarnedCurrency(String currencyName, int amount) callback method in the TJEarnedCurrencyListener you specified. For example if the current currency balance is 100 and the user completes an Offer for 25 currency, the next time getCurrencyBalance() is called, the onEarnedCurrency method will fire with an amount of 25.
// on enable, add delegates
void OnEnable() {
Tapjoy.OnEarnedCurrency += HandleEarnedCurrency;
}
// on disable, remove delegates
void OnDisable() {
Tapjoy.OnEarnedCurrency -= HandleEarnedCurrency;
}
public void HandleEarnedCurrency(string currencyName, int amount) {
Debug.Log("C#: HandleEarnedCurrency: currencyName: " + currencyName + ", amount: " + amount);
}
You will be notified with the currency earned in the OnEarnedCurrency handler you specified, which will pass currencyName and amount earned parameters.
TapjoyAIR.addEventListener(TJEarnedCurrencyEvent.EARNED_CURRENCY, tapjoyEarnedCurrencyEventHandler);
private function tapjoyEarnedCurrencyEventHandler(event:TJEarnedCurrencyEvent):void
{
trace("You can notify user's here that they've just earned " + event.amount + " " + event.currencyName);
}
You will be notified about the currency earned in the TJEarnedCurrencyEvent.EARNED_CURRENCY handler you specified, which will pass a TJEarnedCurrencyEvent object. This object contains currencyName and amount properties.
To spend some amount of virtual currency of a user, call the following method:
// This method call will deduct 10 virtual currencies from the user's total.
[Tapjoy spendCurrency:10 completion:^(NSDictionary *parameters, NSError *error) {
if (error) {
NSLog(@"spendCurrency error: %@", [error localizedDescription]);
} else {
NSLog(@"spendCurrency returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue])
}
}];
As described above, you will be notified about the currency balance in the completion block, with the parameter “currencyName” providing the name of the currency and “amount” providing the user’s balance.
Tapjoy.spendCurrency(10, new TJSpendCurrencyListener() {
@Override
public void onSpendCurrencyResponse(String currencyName, int balance) {
Log.i("Tapjoy", currencyName + ": " + balance);
}
@Override
public void onSpendCurrencyResponseFailure(String error) {
Log.i("Tapjoy", "spendCurrency error: " + error);
}
});
You will be notified with the currency balance in the onSpendCurrencyResponse(String currencyName, int balance) callback method in the TJSpendCurrencyListener you specified. You will be notified of errors in the onSpendCurrencyResponseFailure(String error) method.
// Spend currency
Tapjoy.SpendCurrency(10);
// on enable, add delegates
void OnEnable() {
Tapjoy.OnSpendCurrencyResponse += HandleSpendCurrencyResponse;
Tapjoy.OnSpendCurrencyResponseFailure += HandleSpendCurrencyResponseFailure;
}
// on disable, remove delegates
void OnDisable() {
Tapjoy.OnSpendCurrencyResponse -= HandleSpendCurrencyResponse;
Tapjoy.OnSpendCurrencyResponseFailure -= HandleSpendCurrencyResponseFailure;
}
public void HandleSpendCurrencyResponse(string currencyName, int balance) {
Debug.Log("C#: HandleSpendCurrencyResponse: currencyName: " + currencyName + ", balance: " + balance);
}
public void HandleSpendCurrencyResponseFailure(string error) {
Debug.Log("C#: HandleSpendCurrencyResponseFailure: " + error);
}
You will be notified about the currency balance in the OnSpendCurrencyResponse handler you specified, which will pass currencyName and balance parameters. You will be notified of an error in the OnSpendCurrencyResponseFailure handler.
try {
let result = await Tapjoy.spendCurrency(10);
let currencyName = result['currencyName'];
let amount = result['amount'];
} catch (error: any) {
//Handle error
}
We use a promise in React Native for spendCurrency()
which takes the amount as a parameter. The promise resolves with a dictionary or an error (which should be caught). The dictionary key currencyName
holds a String with the currency amount.
// Spend currency
TapjoyAIR.spendCurrency(10);
// Setup handlers
TapjoyAIR.addEventListener(TJCurrencyEvent.SPEND_CURRENCY_SUCCESS, tapjoyCurrencyEventHandler);
TapjoyAIR.addEventListener(TJCurrencyEvent.SPEND_CURRENCY_FAILURE, tapjoyCurrencyEventHandler);
private function tapjoyCurrencyEventHandler(event:TJCurrencyEvent):void {
trace("Tapjoy sample event listener for " + event.type + ", " + event.balance + ", " + event.currencyName);
}
You will be notified about the currency balance in the TJCurrencyEvent.SPEND_CURRENCY_SUCCESS handler you specified, which will pass a TJCurrencyEvent object. This object contains currencyName and balance properties. You will be notified of an error in the TJCurrencyEvent.SPEND_CURRENCY_FAILURE handler.
Apologies for any inconvenience, but any new apps that wish to use this feature, needs to consult with their account manager to get approval.
To award some amount of virtual currency of a user, call the following method:
// This method call will award 10 virtual currencies to the user's total.
[Tapjoy awardCurrency:10 completion:^(NSDictionary *parameters, NSError *error) {
if (error) {
NSLog(@"awardCurrency error: %@", [error localizedDescription]);
} else {
NSLog(@"awardCurrency returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue])
}
}];
As described above, you will be notified about the currency balance in the completion block, with the parameter “currencyName” providing the name of the currency and “amount” providing the user’s balance.
Tapjoy.awardCurrency(10, new TJAwardCurrencyListener() {
@Override
public void onAwardCurrencyResponseFailure(String error) {
Log.i("Tapjoy", "awardCurrency error: " + error); }
@Override
public void onAwardCurrencyResponse(String currencyName, int balance) {
Log.i("Tapjoy", currencyName + ": " + balance);
}
});
You will be notified with the currency balance in the onAwardCurrencyResponse(String currencyName, int balance) callback method in the TJAwardCurrencyListener you specified.
// Award currency
Tapjoy.AwardCurrency(10);
// on enable, add delegates
void OnEnable() {
Tapjoy.OnAwardCurrencyResponse += HandleAwardCurrencyResponse;
Tapjoy.OnAwardCurrencyResponseFailure += HandleAwardCurrencyResponseFailure;
}
// on disable, remove delegates
void OnDisable() {
Tapjoy.OnAwardCurrencyResponse -= HandleAwardCurrencyResponse;
Tapjoy.OnAwardCurrencyResponseFailure -= HandleAwardCurrencyResponseFailure;
}
public void HandleAwardCurrencyResponse(string currencyName, int balance) {
Debug.Log("C#: HandleAwardCurrencySucceeded: currencyName: " + currencyName + ", balance: " + balance);
}
public void HandleAwardCurrencyResponseFailure(string error) {
Debug.Log("C#: HandleAwardCurrencyResponseFailure: " + error);
}
You will be notified about the currency balance in the OnAwardCurrencyResponse handler you specified, which will pass currencyName and balance parameters. You will be notified of an error in the OnAwardCurrencyResponseFailure handler.
try {
let result = await Tapjoy.awardCurrency(10);
let currencyName = result['currencyName'];
let amount = result['amount'];
} catch (error: any) {
//Handle error
}
We use a promise in React Native for awardCurrency()
which takes the amount as a parameter. The promise resolves with a dictionary or an error (which should be caught). The dictionary key currencyName
holds a String with the currency amount.
// Award currency
TapjoyAIR.awardCurrency(10);
// Setup handlers
TapjoyAIR.addEventListener(TJCurrencyEvent.AWARD_CURRENCY_SUCCESS, tapjoyCurrencyEventHandler);
TapjoyAIR.addEventListener(TJCurrencyEvent.AWARD_CURRENCY_FAILED, tapjoyCurrencyEventHandler);
private function tapjoyCurrencyEventHandler(event:TJCurrencyEvent):void {
trace("Tapjoy sample event listener for " + event.type + ", " + event.balance + ", " + event.currencyName);
}
You will be notified about the currency balance in the TJCurrencyEvent.AWARD_CURRENCY_SUCCESS handler you specified, which will pass a TJCurrencyEvent object. This object contains currencyName and balance properties. You will be notified of an error in the TJCurrencyEvent.AWARD_CURRENCY_FAILURE handler.
If you want to view test offers in the Offerwall, you can add a test device to your application. This will allow a test offer to appear at the top of the Offerwall so you can easily test currency
Another tool you can use to verify that your Tapjoy Managed Currency implementation is working correctly is the "Get User Balance" tool on the Tapjoy dashboard:
If your app shows a different balance for a user than what this tool shows, it is likely your app has gotten out of synch with the Tapjoy balance. Usually this can be corrected by making sure your app calls getCurrencyBalance sufficiently frequently.
NOTE: It’s important to note that while Tapjoy does its best to reward users as quickly as possibly we can’t guarantee that the user will be rewarded instantaneously. There are a lot of factors that determine how long it may take to reward a user. As a best practice, in addition to checking when the video ad closes you should check for an updated balance at regular intervals and after certain app events like app launch, app resume, in between levels, before your store loads, etc. We also recommend that you let your users know that it may take some time before an offer gets completed.