プレイヤーに広告を表示することにより、ゲームを収益化することができます。現在のところ、インスタントゲームに統合されているAudience Networkの広告には、動画リワードとインタースティシャル広告の2つの形式があります。このセクションでは、広告収益化をインスタントゲームに統合するプロセスについて説明します。
プラットフォーム | インタースティシャル | インタースティシャルリワード | 動画リワード |
---|---|---|---|
Android | ✅ | ✅ | ✅ |
iOS | ✅ | ✅ | ✅ |
モバイルサイト | ✅ | ✅ | ✅ |
デスクトップウェブ | ✅ | ✅ | ✅ |
注: Audience Networkは、現時点で特定の地域のみに限定されています。Audience Networkオンボーディングフローで利用可能かどうか確認してください。
詳しくは、Audience Network: インスタントゲームの収益化を始めるための5つのステップをご覧ください。
Facebookアプリを設定するすでにアプリに収益化マネージャを設定し、広告の配置を作成してある場合、デモをダウンロードすることにより下のサンプルコードを実際に動かすことができます。
広告デモをダウンロードする(.zip)インタースティシャルは、アプリ内の自然な移行ポイントでフルスクリーン表示される広告です。インタースティシャルは、自動再生またはクリック再生の形式で存在します。自動再生広告は、インタースティシャルが読み込まれたらすぐに再生されます。デフォルトでは、それらは3秒後にスキップできるようになります。広告の掲載期間は最大2分間です。
下記のコードスニペットは、インタースティシャル広告を表示する方法を示す例です。
このコードが動作するためには、まずインタースティシャル表示フォーマットで広告配置を作成する必要があります。アプリ内の広告ユニットごとに異なる配置を使ってください。
var preloadedInterstitial = null; FBInstant.getInterstitialAdAsync( '123123123123_123123123123' // Your Ad Placement Id ).then(function(interstitial) { // Load the Ad asynchronously preloadedInterstitial = interstitial; return preloadedInterstitial.loadAsync(); }).then(function() { console.log('Interstitial preloaded'); }).catch(function(err){ console.error('Interstitial failed to preload: ' + err.message); });
preloadedInterstitial.showAsync() .then(function() { // Perform post-ad success operation console.log('Interstitial ad finished successfully'); }) .catch(function(e) { console.error(e.message); });
インタースティシャルリワードは、ユーザーに対して、広告を見る代わりにインセンティブを提供する全画面広告です。それらの広告でユーザーにオプトインを要求することはありません。
下記のコードスニペットは、インタースティシャルリワード広告を表示する方法を示す例です。
このコードが動作するためには、まずインタースティシャルリワード表示フォーマットで広告配置を作成する必要があります。インタースティシャルリワード広告は、Facebook Gamingアプリ、モバイルウェブアプリ、デスクトップウェブアプリで利用可能です。アプリ内の広告ユニットごとに異なる配置を使ってください。
var preloadedRewardedInterstitial = null; FBInstant.getRewardedInterstitialAsync( '123123123123_123123123123' // Your Ad Placement Id ).then(function(rewarded) { // Load the Ad asynchronously preloadedRewardedInterstitial = rewarded; return preloadedRewardedInterstitial.loadAsync(); }).then(function() { console.log('Rewarded interstitial preloaded'); }).catch(function(err){ console.error('Rewarded interstitial failed to preload: ' + err.message); });
preloadedRewardedInterstitial.showAsync() .then(function() { // Perform post-ad success operation console.log('Rewarded interstitial watched successfully'); }) .catch(function(e) { console.error(e.message); });
動画リワード広告は、利用者が動画広告を視聴することの引き換えに、仮想通貨、アプリ内アイテム、限定コンテンツといった何らかの特典を得られる、フルスクリーンの広告サービスです。
下記のコードスニペットは、動画リワード広告を表示する方法を示す例です。
このコードが動作するためには、まず動画リワード表示フォーマットで広告配置を作成する必要があります。アプリ内の広告ユニットごとに異なる配置を使ってください。
var preloadedRewardedVideo = null; FBInstant.getRewardedVideoAsync( '456456456456_456456456456' // Your Ad Placement Id ).then(function(rewarded) { // Load the Ad asynchronously preloadedRewardedVideo = rewarded; return preloadedRewardedVideo.loadAsync(); }).then(function() { console.log('Rewarded video preloaded'); }).catch(function(err){ console.error('Rewarded video failed to preload: ' + err.message); });
preloadedRewardedVideo.showAsync() .then(function() { // Perform post-ad success operation console.log('Rewarded video watched successfully'); }) .catch(function(e) { console.error(e.message); });
同じタイプの3つの広告インスタンスを事前読み込みしたが、表示しなかった場合、新しい広告を作成しようとする際にエラーになります。広告が正常に読み込まれたなら、その広告は60分間有効になります。
その動作について理解を深めるため、下記のサンプルコードをご覧ください。ここでは、すべてが(有効な広告配置IDなど)適切に構成されていて、ネットワークに問題がないことが前提となっています。
var preloadedInterstitial1 = null; var preloadedInterstitial2 = null; var preloadedInterstitial3 = null; var preloadedRewardedVideo = null; // PRELOAD PHASE FBInstant.getInterstitialAdAsync( '123123123123_123123123123' ).then(function(interstitial) { // This should get called, meaning you now have 1 ad instance. preloadedInterstitial1 = interstitial; return preloadedInterstitial1.loadAsync(); }).then(function() { // This should get called unless we do not have ads to serve. console.log('Interstitial 1 preloaded') }).catch(function(err){ // This would be called only if we do not have ads to serve. // The error would then be ADS_NO_FILL. // You can try to reload the ad after some time (ideally over 30 seconds). // If you get ADS_NO_FILL 3 times in a row, the instance will be disabled. console.error('Interstitial 1 failed to preload: ' + err.message); // You can try to reload after 30 seconds (2nd attempt) setTimeout(function () { handleAdsNoFill(preloadedInterstitial1, 2); }, 30 * 1000); }); // Here is how the function to handle ADS_NO_FILL would look like function handleAdsNoFill (adInstance, attemptNumber) { if (attemptNumber > 3) { // You can assume we will not have to serve in the current session, no need to try // to load another ad. return; } else { adInstance.loadAsync().then(function() { // This should get called if we finally have ads to serve. console.log('Interstitial preloaded') }).catch(function(err){ console.error('Interstitial failed to preload: ' + err.message); // You can try to reload after 30 seconds setTimeout(function () { handleAdsNoFill(adInstance, attemptNumber+1); }, 30 * 1000); }); } } // As we covered ADS_NO_FILL, from now on let's assume we have ads to serve. FBInstant.getInterstitialAdAsync( // You can re-use the same Ad Placement Id as long as it is of the valid type: // interstitial or rewarded video (here, it has to be interstitial) '123123123123_123123123123' ).then(function(interstitial) { // This should get called, meaning you now have 2 ad instances. preloadedInterstitial2 = interstitial; return preloadedInterstitial2.loadAsync(); }).then(function() { console.log('Interstitial 2 preloaded') }); FBInstant.getRewardedVideoAsync( '456456456456_456456456456' ).then(function(rewarded) { // This should get called, meaning you now have 3 ad instances. preloadedRewardedVideo = rewarded; return preloadedRewardedVideo.loadAsync(); }).then(function() { console.log('Rewarded video preloaded') }); FBInstant.getInterstitialAdAsync( '123123123123_123123123123' ).catch(function(err){ // This should be called now because you already have 3 ad instances. // The error would then be ADS_TOO_MANY_INSTANCES. console.error('Interstitial 3 failed to preload: ' + err.message); }); // SHOWING ADS (at a timing that makes sense in the workflow of your game) preloadedInterstitial1.showAsync() .then(function() { // This should get called, meaning you now have 2 ad instances. console.log('Interstitial ad 1 finished successfully'); }); // A bit later, assuming you did not preload a new instance yet. preloadedInterstitial2.showAsync() .then(function() { // This should get called, meaning you now have 1 ad instance. console.log('Interstitial ad finished successfully'); }); // A bit later, assuming you did not preload a new instance yet. preloadedRewardedVideo.showAsync() .then(function() { // This should get called, meaning you now have no ad instance. console.log('Rewarded video watched successfully'); });
以下は、インスタントゲームに固有の情報です。Audience Networkインサイトもご覧ください。
広告の適切なタイミング。ゲーム中の広告が、プレイヤーの邪魔をしないようにしてください。
広告の事前読み込み。最後の瞬間まで待ってから、広告のリクエスト、事前読み込み、表示を同時にすることがないようにしてください。むしろ、いくつかのAdInstanceを事前に読み込んでおき、プレイヤーがその表示をリクエストした時点で待ち時間が長くならないようにします。
サポートの確認。場合によっては、プレイヤーのセッションが広告をサポートしていないことがあります(デスクトップブラウザーでプレイしている場合など)。広告リクエストをする前に、広告がサポートされているかどうかをFBInstant.getSupportedAPIs()
で必ずチェックしてください。
「埋まらない」状況のための穏便な処理を実装する。条件によっては、広告枠が埋まらない場合があります。その場合、ADS_NO_FILL
のエラーメッセージが出て、履行が却下されます。ゲームでは、それを穏便に処理して友好的なメッセージを表示し、同じタイプの別の広告をリクエストする前に30秒待つようにしてください。
提出前に広告をテストする。アプリの開発者は、アプリをAudience Network審査に提出する前であっても、モバイルで広告をリクエストして、うまく連携していることを確認することができます。
広告インプレッションをトラッキングする。カスタムイベントを使うことにより、showAsync
解決時に広告インプレッションをトラッキングすることができます。
保持するAdInstanceが多すぎないようにする。getRewardedVideoAsync
とgetInterstitialAdAsync
のどちらのメソッドも、AdInstance
を返します。これは、事前読み込みが可能です。3つ以上の同じタイプのAdInstanceを、事前読み込みしたが表示しなかった場合、それ以降に新しいAdInstanceを作成しようとすると失敗します。つまり、showAsync
が呼び出されるか、またはプレイヤーがMessengerを再開するまで、getRewardedVideoAsync
とgetInterstitialAdAsync
の呼び出しは、エラーコードADS_TOO_MANY_INSTANCES
で失敗します。