컴패니언 광고 지원 추가
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 가이드는 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는 유동 크기 컴패니언 사용도 지원합니다.
companionAdSlots
를 만든 후에는 AdsLoader
에 추가해야 합니다. 다음 예에서는 Exoplayer-IMA 확장 프로그램을 사용하는 IMA Android BasicExample을 사용하는지 아니면 확장 프로그램을 사용하지 않는 다른 IMA 구현을 사용하는지에 따라 이 작업을 수행하는 방법을 보여줍니다.
BasicExample
adsLoader = new ImaAdsLoader.Builder(this).setCompanionAdSlots(companionAdSlots).build();
기타 구현
adsLoader.getAdDisplayContainer().setCompanionSlots(companionAdSlots);
다음은 이제 애플리케이션에 컴패니언 광고가 표시됩니다.
유동형 컴패니언 광고 표시
이제 IMA에서 유동 컴패니언 광고를 지원합니다. 이러한 동반 광고는 광고 슬롯의 크기에 맞게 크기를 조절할 수 있습니다. 상위 뷰의 너비를 100% 채운 다음, 동반 앱의 콘텐츠에 맞게 높이를 조정합니다. Ad Manager에서 Fluid
컴패니언 크기를 사용하여 설정됩니다. 이 값을 설정할 위치는 다음 이미지를 참고하세요.
원활한 동반자를 위해 Android 앱 업데이트
CompanionAdSlot.FLUID_SIZE
을 두 매개변수로 사용하도록 CompanionAdSlot.setSize()
메서드를 업데이트하여 유동형 컴패니언 슬롯을 선언할 수 있습니다.
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);
FAQ
- 가이드를 따랐는데 컴패니언 광고가 표시되지 않습니다. 어떻게 해야 하나요?
- 먼저 태그가 실제로 동반자를 반환하는지 확인합니다. 이렇게 하려면 웹브라우저에서 태그를 열고 CompanionAds 태그를 찾습니다. 이 경우 반환되는 동반 광고의 크기가
CompanionAdSlot
객체에 전달하는 크기와 동일한지 확인하세요.
- 이 가이드에 따라 광고를 만들면 동반 광고 슬롯은 어떻게 표시되나요?
-
아래 이미지는
BasicExample
에서 생성되었으며, 위에는 콘텐츠 동영상이 재생되고 아래에는 컴패니언 광고가 표시됩니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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"]]