コンパニオン広告のサポートを追加
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
プラットフォームを選択:
HTML5
Android
iOS
このガイドは、Android IMA 実装にコンパニオン広告を追加することに関心のあるパブリッシャー様を対象としています。
前提条件
- IMA SDK が統合された Android アプリケーション。SDK が統合されたアプリがまだない場合は、BasicExample をご覧ください。
- コンパニオン広告を返すように設定された広告タグ。
役立つ入門ガイド
アプリに IMA SDK を実装する必要がある場合は、スタートガイドをご覧ください。
コンパニオン広告をアプリに追加する
コンパニオンを表示する ViewGroup を作成する
コンパニオンをリクエストする前に、レイアウト内にコンパニオン用のスペースを作成する必要があります。レイアウト XML に ViewGroup
要素を追加します。この例では LinearLayout
を使用しています。後のステップで、この要素への参照を AdDisplayContainer
に渡します。BasicExample アプリに統合する場合は、videoPlayerContainer
の下の
activity_my.xml
に追加します。
activity_my.xml
<LinearLayout
android:id="@+id/companionAdSlot"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="vertical"
android:textAlignment="center" />
CompanionAdSlot を作成する
次のステップでは、CompanionAdSlot
オブジェクトをビルドし、ArrayList<CompanionAdSlot>
に追加します。AdDisplayContainer
はコンパニオン広告スロットのリストを受け取るため、複数のコンパニオン広告を一度に表示できます。CompanionAdSlot
を作成するには、ImaSdkFactory
のインスタンスを作成する必要があります。
ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);
CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
companionAdSlot.setContainer(companionViewGroup);
companionAdSlot.setSize(300, 250);
ArrayList<CompanionAdSlot> companionAdSlots = new ArrayList<CompanionAdSlot>();
companionAdSlots.add(companionAdSlot);
アプリで表示するコンパニオンのサイズごとにコンパニオン広告スロットを作成します。IMA SDK は、ビューの高さと幅に一致するディメンションを持つ VAST レスポンスのコンパニオンをコンパニオン広告スロットに挿入します。IMA SDK は、Fluid サイズのコンパニオンの使用にも対応しています。companionAdSlots
を作成したら、AdsLoader
に追加する必要があります。次の例は、Exoplayer-IMA 拡張機能を使用する IMA Android BasicExample を使用しているか、拡張機能を使用しない他の IMA 実装を使用しているかに応じて、この処理を行う方法を示しています。
BasicExample
adsLoader = new ImaAdsLoader.Builder(this).setCompanionAdSlots(companionAdSlots).build();
その他の実装
adsLoader.getAdDisplayContainer().setCompanionSlots(companionAdSlots);
これで操作は完了です。これで、コンパニオン広告が表示されるようになりました。
Fluid コンパニオン広告を表示する
IMA で、Fluid サイズのコンパニオン広告がサポートされるようになりました。これらのコンパニオン広告は、広告スロットのサイズに合わせてサイズ変更できます。親ビューの幅いっぱいに表示され、コンパニオンのコンテンツに合わせて高さが調整されます。コンパニオン広告のサイズは、アド マネージャーの Fluid
コンパニオン広告のサイズを使用して設定します。この値を設定する場所については、次の画像をご覧ください。
流動的なコンパニオンのための Android アプリの更新
CompanionAdSlot.setSize()
メソッドを更新して、両方のパラメータとして CompanionAdSlot.FLUID_SIZE
を受け取るようにすることで、流動的なコンパニオン スロットを宣言できます。
ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);
CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
companionAdSlot.setContainer(companionViewGroup);
companionAdSlot.setSize(CompanionAdSlot.FLUID_SIZE, CompanionAdSlot.FLUID_SIZE);
ArrayList<CompanionAdSlot> companionAdSlots = new ArrayList<CompanionAdSlot>();
companionAdSlots.add(companionAdSlot);
よくある質問
- ガイドに沿って設定しましたが、コンパニオン広告が表示されません。必要な対策
- まず、タグが実際にコンパニオンを返していることを確認します。これを行うには、ウェブブラウザでタグを開き、CompanionAds タグを探します。その場合は、返されるコンパニオンのサイズが
CompanionAdSlot
オブジェクトに渡しているサイズと同じであることを確認してください。 - このガイドに沿ってコンパニオン広告スロットを作成すると、どのような表示になりますか?
-
下の画像は
BasicExample
から作成されたもので、コンテンツ動画が上に再生され、コンパニオン広告が下に表示されています。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-31 UTC。
[null,null,["最終更新日 2025-08-31 UTC。"],[[["\u003cp\u003eThis guide helps publishers integrate companion ads into their Android applications using the IMA SDK.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers need an Android app with the IMA SDK and an ad tag configured to return companion ads to begin.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a ViewGroup in the layout, a CompanionAdSlot object, and adding it to the AdsLoader.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA SDK supports fluid companion ads that resize to fit the ad slot using \u003ccode\u003eCompanionAdSlot.FLUID_SIZE\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting tips are provided for common issues, such as not seeing companion ads after implementation.\u003c/p\u003e\n"]]],[],null,["Select platform: [HTML5](/interactive-media-ads/docs/sdks/html5/client-side/companions \"View this page for the HTML5 platform docs.\") [Android](/interactive-media-ads/docs/sdks/android/client-side/companions \"View this page for the Android platform docs.\") [iOS](/interactive-media-ads/docs/sdks/ios/client-side/companions \"View this page for the iOS platform docs.\")\n\nThis guide is intended for publishers interested in adding companion ads to\ntheir Android IMA implementation.\n\nPrerequisites\n\n- Android application with the IMA SDK integrated. See the [BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) if you don't already have an app with the SDK integrated.\n- An ad tag configured to return a companion ad.\n - If you need a sample, check out our [FAQ](/interactive-media-ads/faq#4).\n\nHelpful primers\n\nIf you still need to implement the IMA SDK in your app, check out our [Get\nStarted guide](/interactive-media-ads/docs/sdks/android/client-side/quickstart).\n\nAdd companion ads to your app\n\nCreate a ViewGroup to display your companion\n\nBefore requesting a companion, you need to create a space for it in your\nlayout. In your layout XML, add a `ViewGroup` element; this\nexample uses a `LinearLayout`. In a later step you'll pass a\nreference to this element to your `AdDisplayContainer`.\n\nIf you're\nintegrating into the BasicExample app, add this to [`activity_my.xml`](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/app/src/main/res/layout/activity_my.xml) below the `videoPlayerContainer`.\n\nactivity_my.xml \n\n```scdoc\n\u003cLinearLayout\n android:id=\"@+id/companionAdSlot\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"250dp\"\n android:layout_gravity=\"center_horizontal\"\n android:gravity=\"center\"\n android:orientation=\"vertical\"\n android:textAlignment=\"center\" /\u003e\n```\n\nCreate a CompanionAdSlot\n\nThe next step is to build a `CompanionAdSlot` object, which is\nthen added to an `ArrayList\u003cCompanionAdSlot\u003e`.\n`AdDisplayContainer` takes a list of companion ad slots so you can\ndisplay multiple companion ads at once. You will need to create an instance of\n`ImaSdkFactory` to create the `CompanionAdSlot`. \n\n```text\n ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();\n ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);\n\n CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();\n companionAdSlot.setContainer(companionViewGroup);\n companionAdSlot.setSize(300, 250);\n ArrayList\u003cCompanionAdSlot\u003e companionAdSlots = new ArrayList\u003cCompanionAdSlot\u003e();\n companionAdSlots.add(companionAdSlot);\n```\n\nCreate a companion ad slot for each size of companion you intend to show in your app.\nThe IMA SDK populates the companion ad slot with any companions from the VAST response that\nhave dimensions matching the view's height and width. The IMA SDK also supports using\n[fluid sized companions](/interactive-media-ads/docs/sdks/android/client-side/companions#display-fluid-companion-ads).\nOnce you have created the `companionAdSlots` they needed to be added to the\n`AdsLoader`. The following examples show how to do this depending on whether you\nare using the\n[IMA Android BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) which uses the\n[Exoplayer-IMA extension](//github.com/google/ExoPlayer/tree/release-v2/extensions/ima),\nor other IMA implementations that do not use the extension. \n\nBasicExample \n\n```text\nadsLoader = new ImaAdsLoader.Builder(this).setCompanionAdSlots(companionAdSlots).build();\n```\n\nOther implementations \n\n```text\nadsLoader.getAdDisplayContainer().setCompanionSlots(companionAdSlots);\n```\n\nThat's all there is to it! Your application is now displaying companion\nads.\n\nDisplay fluid companion ads\n\nIMA now supports fluid companion ads. These companions ads can resize to match the size of the ad\nslot. They fill 100% of the width of parent view, then resize their height to fit the companion's\ncontent. They're set by using the `Fluid` companion size in Ad Manager. See the\nfollowing image for where to set this value.\n\nUpdate Android apps for fluid companions\n\nYou can declare a fluid companion slot by updating the\n[`CompanionAdSlot.setSize()`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/CompanionAdSlot#public-abstract-void-setsize-int-width,-int-height)\nmethod to take [`CompanionAdSlot.FLUID_SIZE`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/CompanionAdSlot#public-static-final-int-fluid_size)\nas both parameters. \n\n```scdoc\n ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();\n ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);\n\n CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();\n companionAdSlot.setContainer(companionViewGroup);\n companionAdSlot.setSize(CompanionAdSlot.FLUID_SIZE, CompanionAdSlot.FLUID_SIZE);\n ArrayList\u003cCompanionAdSlot\u003e companionAdSlots = new ArrayList\u003cCompanionAdSlot\u003e();\n companionAdSlots.add(companionAdSlot);\n```\n\nFAQ\n\nI followed the guide, but I'm not seeing companion ads. What should I do?\n: First, check to make sure your tag really is returning companions. To do\n this, open the tag in a web browser and look for a CompanionAds tag. If you see\n that, check to make sure the size of the companion being returned is the same\n size as the dimensions you're passing into the `CompanionAdSlot`\n object.\n\nWhat will my companion ad slot look like when following this guide?\n:\n The image below was created from the [BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) and has the content video playing above with the companion ad below.\n\n \u003cbr /\u003e"]]