Self-Managed Currency
Set up Tapjoy Offerwall with a self-managed virtual currency by configuring reward callbacks and handling transactions on your server.
Read time 8 minutesLast updated 3 hours ago
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. Although 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.
Callback URL
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:The default request parameters include snuid and currency (how much currency should be added to the user's account), and the user's wifi mac_address (if available).<callback_url>?snuid=<user_id>¤cy=<currency>&mac_address=<mac_address> //Example http://www.sampledoman.com/payments/offers/tapjoy?&snuid=42&currency=50&mac\_address=00-16-41-34-2C-A6
Server Response
Tapjoy servers will expect either a200
403
Server response | Cases |
---|---|
|
|
|
|
Tapjoy re-attempts the callback approximately every 5 minutes for 4 days. Tapjoy's algorithm treats the request as a failure if your server takes more than 5 seconds to respond.
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=
Parameter | Description | Notes |
---|---|---|
| An identifier to mark the specific currency awarded which will always be unique. | Represents the
|
| MD5 hash of the id, snuid, currency and secret key. |
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.
Verifier
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.Digest::MD5.hexdigest("#{id}:#{snuid}:#{currency}:#{secret_key}")
Improved Callback URL
We have improved on the callbacks listed above with more information and security. If you would like to use this improved version, contact your account manager or our support team to help you enable this version of the callback. When a user has earned currency by completing an offer, we will make a POST request to the URL you provided. The format of the parameters will be:{ "id": "reward.id", “rev”: 100, “cp”: ”your_custom_string” "currency": { "id": "currency_id", "reward": "xxx", "currency_sale": "", }, "offer": { "name": "Some offer", “type”: “”, “icon_url”: “offer_icon_url, }, “placement”: { “content_type”: “offerwall”, “name”: “placement_name” }, "user": { "id": "pub_user_id" }, “timestamp”: “123491324” }
Parameter | Type | Description |
---|---|---|
id | string | The unique reward id for this request |
rev | double | Revenue in USD Dollars earned |
cp | string | The custom parameter passed through the SDK via the setCustomParameter method |
currency.id | string | The unique identifier for this currency |
currency.reward | integer | Currency amount rewarded to user |
currency.currency_sale | float | Currency sale multiplier (when applicable) |
offer.name | string | Name of the advertiser offer |
offer.type | string | This is not currently supported |
offer.icon_url | string | Icon URL of the offer |
placement.name | string | The placement associated with this conversion |
placement.content_type | string | The type of the placement used |
user.id | string | The user ID passed through the SDK via the setUserID method |
timestamp | timestamp | The timestamp of this transaction |
Example of the Tapjoy header with signature:HMAC_SHA-256(<Request-Body>,<Secret-Key>)
X-Tapjoy-Signature => 7205ccfdfa1fe28cd05a1b56a9508d898cc938aa555a6c18848097fe4ee0975b
User ID
It is critically important that you set a user id if you are using a self-managed currency. This value is what thesnuid
setUserID
// Recommended approach using connect flag
NSDictionary *connectFlags = @{TJC_OPTION_USER_ID : @"<USER_ID_HERE>"};
[Tapjoy connect:@"SDK_KEY_GOES_HERE" options:connectFlags];
// Setting the user id directly
[Tapjoy setUserIDWithCompletion:@"<USER_ID_HERE>" completion:^(BOOL success, NSError *error) {
}];
Setting the user balance
Each time you request a placement you can tell Tapjoy the users current balance. You must set this before requesting the placement content.TJPlacement *placement = [TJPlacement placementWithName:@"placementName" delegate:nil];
[placement setBalance:100 forCurrencyId:@"1234" withCompletion:^(NSError * _Nullable error) {
if (error != nil) {
//Failure
NSString *message = error.localizedDescription;
} else {
//Success
}
}];
Required Amount
If you set the balance you can also set the required amount value on a placement.TJPlacement* placement = [TJPlacement placementWithName:@"placementName" delegate:nil];
placement setRequiredAmount:100 forCurrencyId:@"1234" withCompletion:^(NSError * _Nullable error) {
if (error != nil) {
//Failure
NSString *message = error.localizedDescription;
} else {
//Success
}
}
Reward Callback IP Whitelisting
If your reward callback server require add permission (whitelist) to access, this is the Tapjoy's IP list. (Last modified: 12 May 2024)18.215.207.89 18.235.142.165 23.20.255.113 23.23.134.165 3.210.188.32 3.215.42.140 3.217.209.177 3.218.95.35 3.219.236.53 3.231.137.161
Switching from Tapjoy Managed to Self-managed
If you haven't launched your app yet, you can switch a Tapjoy Managed currency to a Self-Managed currency from the Edit Virtual Currency screen on the Tapjoy dashboard. Be sure to enter a properly formatted URL into the callback URL field - 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 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.
- 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.