ネイティブ オーバーレイ広告
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
スタートガイド
ネイティブ オーバーレイ広告は、プラットフォームに備わっている UI コンポーネントを通じてユーザーに表示されます。これらの広告は、アプリの上にオーバーレイとして表示されます。バナー広告の機能と似ていますが、広告のスタイルをカスタマイズできます。
ネイティブ オーバーレイ広告は、メディエーションと動画広告をサポートしています。これは、ネイティブ広告と比べた場合の大きな利点です。
このガイドでは、Unity アプリにネイティブ オーバーレイ広告を実装する方法と、その過程で注意すべき点を説明します。
前提条件
- スタートガイドの手順を完了していること。
- Unity プラグイン 9.0.0 以降をインポートしていること。
常にテスト広告でテストする
次のサンプルコードには、テスト広告のリクエストに使用できる広告ユニット ID が含まれています。この ID は、どのリクエストに対しても実際の広告ではなくテスト広告を返すように設定されており、安全に使用できます。
ただし、AdMob ウェブ インターフェースでアプリを登録し、アプリで使用する独自の広告ユニット ID を作成した後は、開発中に使用するデバイスを明示的にテストデバイスとして設定する必要があります。
Android
ca-app-pub-3940256099942544/2247696110
iOS
ca-app-pub-3940256099942544/3986624511
ネイティブ オーバーレイ広告を読み込む
ネイティブ オーバーレイ広告の読み込みは、NativeOverlayAd
クラスで静的 Load()
メソッドを使用して行います。読み込まれた NativeOverlayAd
オブジェクトは、完了ハンドラのパラメータとして提供されます。
次のコードでは、NativeOverlayAd
を使用して広告を読み込みます。
// These ad units are configured to always serve test ads.
#if UNITY_ANDROID
private string _adUnitId = "ca-app-pub-3940256099942544/2247696110";
#elif UNITY_IPHONE
private string _adUnitId = "ca-app-pub-3940256099942544/3986624511";
#else
private string _adUnitId = "unused";
#endif
private NativeOverlayAd _nativeOverlayAd;
/// <summary>
/// Loads the ad.
/// </summary>
public void LoadAd()
{
// Clean up the old ad before loading a new one.
if (_nativeOverlayAd != null)
{
DestroyAd();
}
Debug.Log("Loading native overlay ad.");
// Create a request used to load the ad.
var adRequest = new AdRequest();
// Optional: Define native ad options.
var options = new NativeAdOptions
{
AdChoicesPosition = AdChoicesPlacement.TopRightCorner,
MediaAspectRatio = NativeMediaAspectRatio.Any,
};
// Send the request to load the ad.
NativeOverlayAd.Load(_adUnitId, adRequest, options,
(NativeOverlayAd ad, LoadAdError error) =>
{
if (error != null)
{
Debug.LogError("Native Overlay ad failed to load an ad " +
" with error: " + error);
return;
}
// The ad should always be non-null if the error is null, but
// double-check to avoid a crash.
if (ad == null)
{
Debug.LogError("Unexpected error: Native Overlay ad load event " +
" fired with null ad and null error.");
return;
}
// The operation completed successfully.
Debug.Log("Native Overlay ad loaded with response : " +
ad.GetResponseInfo());
_nativeOverlayAd = ad;
// Register to ad events to extend functionality.
RegisterEventHandlers(ad);
});
}
ネイティブ オーバーレイ広告をレンダリングしてスタイルを設定する
ネイティブ オーバーレイ広告は NativeTemplateStyle
を使用してレンダリングされます。このクラスは、広告のスタイルをカスタマイズできるフィールドを定義します。
TemplateID
は必須の文字列で、ネイティブ オーバーレイ広告のレンダリングに使用されるネイティブ テンプレートを定義します。NativeTemplateID
定数を使用して、広告に適したネイティブ テンプレートを選択します。
次のコードは、中サイズのテンプレートとカスタム スタイルを使用して、ネイティブ オーバーレイ広告をレンダリングするものです。
/// <summary>
/// Renders the ad.
/// </summary>
public void RenderAd()
{
if (_nativeOverlayAd != null)
{
Debug.Log("Rendering Native Overlay ad.");
// Define a native template style with a custom style.
var style = new NativeTemplateStyle
{
TemplateID = NativeTemplateID.Medium,
MainBackgroundColor = Color.red,
CallToActionText = new NativeTemplateTextStyles
{
BackgroundColor = Color.green,
FontColor = Color.white,
FontSize = 9,
Style = NativeTemplateFontStyle.Bold
}
};
// Renders a native overlay ad at the default size
// and anchored to the bottom of the screne.
_nativeOverlayAd.RenderTemplate(style, AdPosition.Bottom);
}
}
ネイティブ オーバーレイ広告を表示する / 非表示にする
次のコードは、読み込まれたネイティブ オーバーレイ広告を表示する方法を示しています。
/// <summary>
/// Shows the ad.
/// </summary>
public void ShowAd()
{
if (_nativeOverlayAd != null)
{
Debug.Log("Showing Native Overlay ad.");
_nativeOverlayAd.Show();
}
}
ネイティブ オーバーレイ広告を非表示にする
次のコードは、ネイティブ オーバーレイ広告を非表示にする方法を示しています。
/// <summary>
/// Hides the ad.
/// </summary>
public void HideAd()
{
if (_nativeOverlayAd != null)
{
Debug.Log("Hiding Native Overlay ad.");
_nativeOverlayAd.Hide();
}
}
ネイティブ オーバーレイ広告を破棄する
ネイティブ オーバーレイ広告を使い終わったら、必ず Destroy()
を呼び出してリソースを解放してください。
/// <summary>
/// Destroys the native overlay ad.
/// </summary>
public void DestroyAd()
{
if (_nativeOverlayAd != null)
{
Debug.Log("Destroying native overlay ad.");
_nativeOverlayAd.Destroy();
_nativeOverlayAd = null;
}
}
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-02 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-02 UTC。"],[[["\u003cp\u003eNative overlay ads are presented as an overlay on top of the application, similar to banner ads but with customizable appearances.\u003c/p\u003e\n"],["\u003cp\u003eThese ads support both mediation and video ads, offering a key advantage over traditional native ads.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides instructions on implementing native overlay ads in a Unity app, including loading, rendering, showing, hiding, and destroying the ads.\u003c/p\u003e\n"],["\u003cp\u003eBefore using real ads, it is crucial to test with test ads and configure your device as a test device during development.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can customize the appearance of the native overlay ad by using the \u003ccode\u003eNativeTemplateStyle\u003c/code\u003e and defining template IDs and styles for various elements.\u003c/p\u003e\n"]]],["Native overlay ads are implemented in Unity using the `NativeOverlayAd` class. First, use the `Load()` method with an ad unit ID, `AdRequest`, and `NativeAdOptions` to load an ad. Then, render the ad using `RenderTemplate()` with a `NativeTemplateStyle` to customize its appearance. Control visibility with `Show()` and `Hide()`, and release resources using `Destroy()`. Use test ad unit IDs during development and configure devices for testing.\n"],null,["Select platform: [Android](/admob/android/native \"View this page for the Android platform docs.\") [iOS](/admob/ios/native \"View this page for the iOS platform docs.\") [Flutter](/admob/flutter/native \"View this page for the Flutter platform docs.\") [Unity](/admob/unity/native-overlay \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\nGet started\n\nNative overlay ads are presented to users through UI components that are native\nto the platform. These ads are presented as an overlay on top of the\napplication. This is similar to how banner ads function, but with the ability to\ncustomize the appearance of the ads.\n\nNative overlay ads support mediation and video ads. This is a key advantage\nnative overlay ads have over [native ads](/admob/unity/native).\n\nThis guide shows you how to implement native overlay ads in a Unity app, as well\nas some important things to consider along the way.\n\nPrerequisites\n\n- Complete the [Get started guide](/admob/unity/quick-start).\n- Unity plugin 9.0.0 or higher.\n\nAlways test with test ads\n\nThe following sample code contains an ad unit ID which you can use to request\ntest ads. It's been specially configured to return test ads rather than\nproduction ads for every request, making it safe to use.\n\nHowever, after you've registered an app in the\nAdMob web interface and created your own ad unit\nIDs for use in your app, explicitly [configure your device as a test\ndevice](/admob/unity/test-ads#enable_test_devices) during\ndevelopment. \n\nAndroid\n\n`ca-app-pub-3940256099942544/2247696110`\n\niOS\n\n`ca-app-pub-3940256099942544/3986624511`\n\nLoad the native overlay ad\n\nLoading a native overlay ad is accomplished using the static `Load()` method on\nthe `NativeOverlayAd` class. The loaded `NativeOverlayAd` object is provided as\na parameter in the completion handler.\n\nThe following code uses `NativeOverlayAd` to load an ad: \n\n\n\n // These ad units are configured to always serve test ads.\n #if UNITY_ANDROID\n private string _adUnitId = \"ca-app-pub-3940256099942544/2247696110\";\n #elif UNITY_IPHONE\n private string _adUnitId = \"ca-app-pub-3940256099942544/3986624511\";\n #else\n private string _adUnitId = \"unused\";\n #endif\n\n\n private NativeOverlayAd _nativeOverlayAd;\n\n /// \u003csummary\u003e\n /// Loads the ad.\n /// \u003c/summary\u003e\n public void LoadAd()\n {\n // Clean up the old ad before loading a new one.\n if (_nativeOverlayAd != null)\n {\n DestroyAd();\n }\n\n Debug.Log(\"Loading native overlay ad.\");\n\n // Create a request used to load the ad.\n var adRequest = new AdRequest();\n\n // Optional: Define native ad options.\n var options = new NativeAdOptions\n {\n AdChoicesPosition = AdChoicesPlacement.TopRightCorner,\n MediaAspectRatio = NativeMediaAspectRatio.Any,\n };\n\n // Send the request to load the ad.\n NativeOverlayAd.Load(_adUnitId, adRequest, options,\n (NativeOverlayAd ad, LoadAdError error) =\u003e\n {\n if (error != null)\n {\n Debug.LogError(\"Native Overlay ad failed to load an ad \" +\n \" with error: \" + error);\n return;\n }\n\n // The ad should always be non-null if the error is null, but\n // double-check to avoid a crash.\n if (ad == null)\n {\n Debug.LogError(\"Unexpected error: Native Overlay ad load event \" +\n \" fired with null ad and null error.\");\n return;\n }\n\n // The operation completed successfully.\n Debug.Log(\"Native Overlay ad loaded with response : \" +\n ad.GetResponseInfo());\n _nativeOverlayAd = ad;\n\n // Register to ad events to extend functionality.\n RegisterEventHandlers(ad);\n });\n }\n\nRender and style the native overlay ad\n\nNative overlay ads are rendered using a `NativeTemplateStyle`. This class\ndefines fields that enable you to customize the ad's appearance.\n\nThe `TemplateID` is a required string which defines the native template used to\nrender the native overlay ad. Use the `NativeTemplateID` constant to choose an\nappropriate native template for your ad.\n\nThe following code renders the native overlay ad with a medium template and a\ncustom style. \n\n /// \u003csummary\u003e\n /// Renders the ad.\n /// \u003c/summary\u003e\n public void RenderAd()\n {\n if (_nativeOverlayAd != null)\n {\n Debug.Log(\"Rendering Native Overlay ad.\");\n\n // Define a native template style with a custom style.\n var style = new NativeTemplateStyle\n {\n TemplateID = NativeTemplateID.Medium,\n MainBackgroundColor = Color.red,\n CallToActionText = new NativeTemplateTextStyles\n {\n BackgroundColor = Color.green,\n FontColor = Color.white,\n FontSize = 9,\n Style = NativeTemplateFontStyle.Bold\n }\n };\n\n // Renders a native overlay ad at the default size\n // and anchored to the bottom of the screne.\n _nativeOverlayAd.RenderTemplate(style, AdPosition.Bottom);\n }\n }\n\nShow and hide the native overlay ad\n\nThe following code demonstrates how to show a loaded native overlay ad. \n\n /// \u003csummary\u003e\n /// Shows the ad.\n /// \u003c/summary\u003e\n public void ShowAd()\n {\n if (_nativeOverlayAd != null)\n {\n Debug.Log(\"Showing Native Overlay ad.\");\n _nativeOverlayAd.Show();\n }\n }\n\nHide the native overlay ad\n\nThe following code demonstrates how to hide a native overlay ad. \n\n /// \u003csummary\u003e\n /// Hides the ad.\n /// \u003c/summary\u003e\n public void HideAd()\n {\n if (_nativeOverlayAd != null)\n {\n Debug.Log(\"Hiding Native Overlay ad.\");\n _nativeOverlayAd.Hide();\n }\n }\n\nDestroy the native overlay ad\n\nWhen finished using the native overlay ad, be sure to call `Destroy()` to\nrelease resources. \n\n /// \u003csummary\u003e\n /// Destroys the native overlay ad.\n /// \u003c/summary\u003e\n public void DestroyAd()\n {\n if (_nativeOverlayAd != null)\n {\n Debug.Log(\"Destroying native overlay ad.\");\n _nativeOverlayAd.Destroy();\n _nativeOverlayAd = null;\n }\n }\n\nNext Steps\n\n- Learn more about native ads in our [native ads playbook](//admob.google.com/home/resources/native-ads-playbook/).\n- See [native ads policies and guidelines](https://support.google.com/admob/answer/6329638)."]]