Table of Contents
Self-managed currency is used when you are handling the currency of your users with your own servers. This method can give you more control with your user’s currency but it also means that you are completely responsible for the back-end work for storing and handling the currency amounts for all your users. getCurrencyBalance, awardCurrency, or spendCurrency are only available for Managed Currency. Tapjoy does not provide any client-side/app-side notifications for self-managed currency: you are responsible for notifying the app and your user when we call your callback server. You MUST set up a callback server to work with self-Managed currency.
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, you should check for an updated balance at regular intervals and after certain app events like app launch, app resume, in between levels, video ad close, 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.
Note: Each platform must have its own currency, even if it is self managed.
Follow the instructions below to learn how to set up self-managed currency. To find out how to setup a virtual currency in the dashboard, see here.
When a user has earned currency by completing an offer, we will make an HTTP GET request to this URL. The format of the parameters will be:
e.g. : http://www.sampledoman.com/payments/offers/tapjoy?&snuid=42¤cy=50&mac_address=00-16-41-34-2C-A6
The default request parameters include snuid (See User ID for more details) and currency (how much currency should be added to the user’s account), and the user’s wifi mac_address (if available). If the offer was completed via tapjoy.com, mac_address will be blank.
Tapjoy servers will expect either a 200 or 403 response from your server.
Your server should respond with 200 only if:
- the user has successfully been awarded their currency.
Your server should respond with 403 if:
- the verifier parameter does not match the calculated value
- the snuid parameter is unknown to your system
- if there was any other error that should not be retried.
Tapjoy will continue to retry if Tapjoy servers receive any response other then 200 or 403. (Note that it is very important NOT to actually reward the user if you are giving a non-200 response, as Tapjoy will continue to re-attempt the callback, possibly resulting in large numbers of duplicate rewards.) We’ll retry every 2 minutes for 4 days. We will treat the request as having failed if your server takes more than 5 seconds to respond. NOTE: The response body of the callback URL responses needs to be in UTF-8. If they are not in UTF-8 we will retry even if you return a 200.
Optional Parameters for fraud detection/prevention:
You can access your Virtual Currency Secret Key in Dashboard -> Monetize -> Virtual Currency -> Create/Edit. (This key is different from the Application SDK Key.) Use this Virtual Currency Secret Key to sign the callback:
If a secret key in the Currency is present (
secret_key=) then we will add the following parameters to the callback request:
- id – An identifier to mark the specific currency awarded which will always be unique. (note this is NOT the currency_id, this represents the request_id)
- verifier – a MD5 hash of the id, snuid, currency and secret key (see below)
2 Fraud Scenarios to always look out for:
- If you see a id being reused and/or an incorrect verifier the callback URL is not coming from Tapjoy and should be considered fraudulent.
- If your user id’s contain strictly only integers we recommend that you perform a simple validation to make sure the user ID isn’t being manipulated. For example, Tapjoy considers “001234″ and “1234″ 2 separate user ID’s while your backend server logic may not.
The verifier is computed by taking the MD5 hash of the id, snuid, currency and secret key, separated by colons. In Ruby code, this would be:
Your server should recompute the verifier and reject any requests that do not match. The server should respond with a 403 Forbidden if the verifier doesn’t match.
Note that each application should have a separate secret key. Please do not use the same secret key for all of your applications, as this might lead to a situation where rewarding a user in one application will also reward the user in the other application. Also the id above represents the request_id not currency_id.
There may be scenarios when no callback is preferred. In this case entering NO_CALLBACK for the URL will avoid an un-necessary call to your servers. One common use case is for customers who are using mediation and the mediator is handling all the rewarding. Instead of sending zero rewards from fixed video the NO_CALLBACK can be provided for the URL which will avoid making this call.
The setUserID is the MOST IMPORTANT call that you need to make if you’re managing your own currency. The value set in setUserID is what the snuid is set to in the Callback URL. It should be called as soon as the TapjoyConnect call succeeds on every app launch. Please wait for the TapjoyConnect call to succeed before setting the user ID, but make sure you set it before requesting ad content (In SDK versions 11.7+, Tapjoy implemented success/failure callbacks to our SDK. It may be advisable to build in logic that listens for these callbacks before requesting content). If set incorrectly, your users will not be rewarded and you will not get paid. The setUserID parameter should be set to a unique user ID (typically a number). For data security and GDPR compliance purposes, the setUserID parameter should not include any recognizable or identifiable information, such as a username, real name, or email address. For security and fraud detection purposes, the user ID should be constant for the lifetime of the user. (Do not, for example, use the user ID parameter to communicate information like the user’s level or score.)
Only in the off chance your game doesn’t have unique ID, then we recommend that you set it as follows:
- On iOS 6 or above, call setUserID(“vendor_id:”).
- On iOS 5 or below, call setUserID(“mac_address:
- On cellular Android devices, call setUserID(“device_id:”).
- On wifi-only Android devices (such as a Nexus 7), call setUserID(“device_id:”.)
The User ID can be up to 190 characters long. The value set in setUserID is what the snuid is set to in the Callback URL.
[Tapjoy setUserID:@"userID"]; // only do this call AFTER the Tapjoy Connect call succeeds
Tapjoy.setUserID(String userID); // only do this call AFTER the Tapjoy Connect call succeeds
TROUBLESHOOTING: If you are calling setUserID and the snuid in the callback URL isn’t a value you expect, then you need to call setUserID before the user goes to the in-app offerwall or tapjoy.com to complete offers. Tapjoy will send device id as snuid in the callback URL if there is no userID associated with a device. For example, a user could launch the app but then go to tapjoy.com before your app sends us the userID. To prevent this you need to make sure setUserID is called on every launch after the connect call.
If you have not set the user ID the system will attempt to use the best-available device ID. In most cases this will be the Advertising ID for the device. However, depending on SDK version, device model/version, device OS version, and Google Play Services the exact ID may vary. Other possible values include the Android ID, udid, and mac_address.
Switching from Tapjoy Managed to Self-managed
If you haven’t launched your app to actual users yet, You can switch a Tapjoy Managed currency to a Self-Managed Currency via the Edit Virtual Currency screen in the Tapjoy dashboard. Be sure to put a properly formatted URL(or "NO_CALLBACK") into the callback URL box , otherwise the change will not actually take place.
If you have a live application that has currency managed by Tapjoy, the process of switching is a bit more complex. Here are a few things to consider:
- You’ll need to create a new App with a new SDK Key. This ensures that users who are using an old version of your App that hasn’t upgraded to the latest version won’t be affected. If you use the same SDK Key for the Self-managed currency version of your app, all your users on the Tapjoy managed currency version won’t be rewarded for completing offers.
- You’ll need to disable any Advertising campaigns pointing to the old App ID, and recreate any Advertising campaigns to point to the new App ID.
- Switching to self-managed will require code changes in your app. You will not be able to use getCurrencyBalance, awardCurrency, or spendCurrency as they’re only available for Managed Currency.
- We recommend that you contact your Account Manager before considering making the change.
- It is not possible to switch from a Self-Managed Currency to a Tapjoy Managed Currency. So be certain you wish to make the change before doing so.
To migrate user’s balance, we recommend follow these steps:
- On first launch, use the old SDK Key (with the Tapjoy Managed Currency) and call getCurrencyBalance to retrieve the balance.
- Update your balance with the value returned by getCurrencyBalance.
- On all subsequent launches, use the new SDK Key.