Grow your game Unity Offerwall Offerwall の収益化 Tapjoy 管理通貨 Tapjoy Offerwall の管理通貨を使用すると、Tapjoy のサーバー上にユーザー通貨残高を保存して管理できます。
Tapjoy 管理通貨を利用すると、Tapjoy のサーバーでユーザーのゲーム内通貨の金額を保存して管理できます。この無料サービスは、Tapjoy のパブリッシャー SDK を統合するすべての開発者が利用可能で、アプリにバックエンド通貨ストレージが不要になります。
通貨残高の取得
ユーザーの現在のゲーム内通貨残高を確認するには、プラットフォーム別に詳しく説明されているメソッドを使用します。推奨されるベストプラクティスは、残高の正確性を保つために、 を頻繁に呼び出すことです。残高を確認する主なタイミングとしては、以下のシナリオが発生したときが挙げられます。
アプリの起動
アプリの再開
Tapjoy ビューの終了
プレースメントコンテンツの消去
最良の結果を得るには、広告コンテンツが完了してから約 3.5 秒後に を呼び出します。そうすることで、ゲーム内報酬の更新に十分な処理時間が確保されます。すぐに残高を確認すると、新たに獲得したゲーム内報酬が反映されない場合があります。
通貨残高の取得
Tapjoy はゲーム内報酬を迅速に付与できるよう取り組んでいます。しかし、ネットワークの遅延などにより、ゲーム内報酬の即座の付与は保証されません。オファーからのゲーム内報酬が表示されるまでに時間がかかる場合があることを、ユーザーに通知してください。正確性を保つため、残高を定期的に、さらには主要なアプリイベント発生時 (以下のイベント発生時など) にも確認してください。
アプリの起動
アプリの再開
レベル間
ストアのロード前
通貨残高を取得するには、以下のプラットフォーム別のメソッドを参照してください。
iOS デバイスで現在のゲーム内通貨残高を取得するには、以下のメソッドを使用します。 // 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]); } }];
完了ブロックでは、残高が返されます。 は通貨の名前、 はユーザーの合計残高です。実装の詳細については、SDK パッケージのサンプルアプリケーションを参照してください。 Android デバイスで現在のゲーム内通貨残高を取得するには、以下のメソッドを使用します。 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); } });
残高は onGetCurrencyBalanceResponse コールバックで受け取り、エラーは onGetCurrencyBalanceResponseFailure で受け取ります。正確性を保つため、アプリの開始時や再開時に を呼び出します。支出および付与のコールバックでも合計残高が返されるため、アプリの更新に利用できます。 // 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); }
通貨残高は、指定した OnGetCurrencyBalanceResponse ハンドラーで通知されます。このハンドラーは と のパラメーターを渡します。エラーは、OnGetCurrencyBalanceResponseFailure ハンドラーで通知されます。 try { let result = await Tapjoy.getCurrencyBalance(); let currencyName = result['currencyName']; let amount = result['amount']; } catch (error: any) { //Handle error }
React Native では、 にパラメーターを取らない promise を使用します。promise は と を含むディクショナリで解決され、失敗した場合はエラーとなります。 // 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); }
通貨残高は、指定した TJCurrencyEvent.GET_CURRENCY_BALANCE_SUCCESS ハンドラーで通知されます。このハンドラーは オブジェクトを渡します。このオブジェクトには と のプロパティが含まれます。エラーは、TJCurrencyEvent.GET_CURRENCY_BALANCE_FAILURE ハンドラーで通知されます。
ユーザーが通貨を獲得したかどうかの確認
最後の残高確認以降にユーザーが通貨を獲得した場合はユーザーに通知します。以下のセクションに記載されているプラットフォーム別の手順を使用して、通知を設定します。
iOS デバイスで獲得した通貨を検出するには、通知オブザーバーを加えます。 // Set the notification observer for earned-currency-notification.これは applicationDidBecomeActive メソッド内に配置することをお勧めします。 [[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]; }
ユーザーが (オファーなどを通じて) ゲーム内通貨を獲得するたびに通知を受けるには、以下のメソッドを使用して獲得通貨リスナーを設定します。 // 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); } });
獲得した通貨の通知は、 内の onEarnedCurrency(String currencyName, int amount) コールバックで受け取ります。例えば、ユーザーの残高が 100 で、オファーから 25 を獲得した場合、次回 を呼び出すと、 がトリガーされ、amount が 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); }
獲得した通貨は、指定した ハンドラーで通知されます。このハンドラーは と獲得した のパラメーターを渡します。 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); }
獲得した通貨は、指定した earned in the TJEarnedCurrencyEvent.EARNED_CURRENCY ハンドラーで通知されます。このハンドラーは TJEarnedCurrencyEvent object を渡します。このオブジェクトには と のプロパティが含まれます。
Tapjoy 管理通貨の支出
ユーザーのゲーム内通貨を支出するには、以下のセクションで詳しく説明されているプラットフォーム別のメソッドを呼び出します。
// 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]); } }];
通貨残高は完了ブロックで通知されます。パラメーター は通貨の名前を示し、 はユーザーの残高を示します。 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); } });
通貨残高は、指定した の onSpendCurrencyResponse(String currencyName, int balance) コールバックメソッドで通知されます。エラーは、onSpendCurrencyResponseFailure(String error) メソッドで通知されます。 // 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); }
通貨残高は、指定した ハンドラーで通知されます。このハンドラーは と のパラメーターを渡します。エラーは、OnSpendCurrencyResponseFailure ハンドラーで通知されます。 try { let result = await Tapjoy.spendCurrency(10); let currencyName = result['currencyName']; let amount = result['amount']; } catch (error: any) { //Handle error }
React Native では、 にパラメーターとして を取る promise を使用します。Promise はディクショナリまたはエラー (検出される) で解決されます。ディクショナリキー は、通貨金額が含まれる文字列を保持します。 // 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); }
通貨残高は、指定した TJCurrencyEvent.SPEND_CURRENCY_SUCCESS ハンドラーで通知されます。このハンドラーは オブジェクトを渡します。このオブジェクトには と のプロパティが含まれます。エラーは、TJCurrencyEvent.SPEND_CURRENCY_FAILURE ハンドラーで通知されます。
Tapjoy 管理通貨の付与
注意
新しいアプリでこの機能を利用する場合は、アカウントマネージャーに連絡して承認を得てください。
ゲーム内通貨をユーザーに付与するには、以下のセクションで詳しく説明されているプラットフォーム別のメソッドを使用します。
// 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]); } }];
通貨残高は ブロックで通知されます。パラメーター は通貨の名前を示し、 はユーザーの残高を示します。 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); } });
通貨残高は、指定した の onAwardCurrencyResponse(String currencyName, int balance) コールバックメソッドで通知されます。 // 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); }
通貨残高は、指定した ハンドラーで通知されます。このハンドラーは と のパラメーターを渡します。エラーは、OnAwardCurrencyResponseFailure ハンドラーで通知されます。 try { let result = await Tapjoy.awardCurrency(10); let currencyName = result['currencyName']; let amount = result['amount']; } catch (error: any) { //Handle error }
React Native では、 にパラメーターとして を取る promise を使用します。Promise はディクショナリまたはエラー (検出される) で解決されます。ディクショナリキー は、通貨金額が含まれる文字列を保持します。 // 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); }
通貨残高は、指定した TJCurrencyEvent.AWARD_CURRENCY_SUCCESS ハンドラーで通知されます。このハンドラーは オブジェクトを渡します。このオブジェクトには と のプロパティが含まれます。エラーは、TJCurrencyEvent.AWARD_CURRENCY_FAILURE ハンドラーで通知されます。
Tapjoy 管理通貨のテスト
Offerwall でオファーをテストするには、アプリケーションにテストデバイスを加えます。これにより、Offerwall の上部に検証用のテストオファーが表示されます。
と の呼び出しを必ず検証し、これらの呼び出しが成功した場合のみコンテンツをロック解除します。失敗した場合、デバイス上の残高に影響を与える可能性があります。
ローカルに保存されている通貨のみに依存せず、Tapjoy のサーバーを利用して正確性を保ちます。
spendCurrency は、コンテンツをロック解除するために通貨を差し引く場合にのみ呼び出します。
管理通貨はアプリ ID ごとに 1 つの通貨のみをサポートします。複数の通貨がある場合は、自己管理通貨を使用します。
Tapjoy では、通貨残高がデバイスごと、アプリごとに保存されるため、デバイス間で残高を共有することはできません。
Tapjoy はゲーム内報酬を迅速に付与することを目指していますが、さまざまな要因によって通貨の付与が遅れる場合があります。主要なアプリイベントの後に定期的に残高を確認し、ユーザーに遅延の可能性があることを通知します。