插頁式廣告
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
插頁式廣告是會全螢幕覆蓋應用程式介面的廣告,通常出現在應用程式流程中的自然轉換點,比如畫面切換階段或遊戲關卡之間的空檔。應用程式顯示插頁式廣告時,使用者可以點選廣告前往連結目標網址,或關閉廣告返回應用程式。
本指南說明如何在 Flutter 應用程式中整合插頁式廣告。
請務必使用測試廣告進行測試
建構及測試應用程式時,請務必使用測試廣告,而非實際的正式廣告;若未遵守此規定,可能導致帳戶遭到停權。
如要載入測試廣告,最簡單的方法是使用插頁式廣告專用的測試廣告單元 ID:
/21775744923/example/interstitial
測試廣告單元會在每次請求時傳回測試廣告。在編寫程式碼、測試及偵錯階段,您可以自由在應用程式中使用這些廣告單元,但發布前記得要換成自己的廣告單元 ID。
載入廣告
以下是載入插頁式廣告的程式碼範例:
請將 _adUnitId 替換為您的廣告單元 ID。
插頁式廣告事件
您可以使用 FullScreenContentCallback
監聽生命週期事件,例如廣告顯示或關閉的時刻。只要在顯示廣告前設定 AdManagerInterstitialAd.fullScreenContentCallback
,即可接收這些事件通知。以下示範如何實作每個方法:
ad.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
// Called when the ad showed the full screen content.
debugPrint('Ad showed full screen content.');
},
onAdFailedToShowFullScreenContent: (ad, err) {
// Called when the ad failed to show full screen content.
debugPrint('Ad failed to show full screen content with error: $err');
// Dispose the ad here to free resources.
ad.dispose();
},
onAdDismissedFullScreenContent: (ad) {
// Called when the ad dismissed full screen content.
debugPrint('Ad was dismissed.');
// Dispose the ad here to free resources.
ad.dispose();
},
onAdImpression: (ad) {
// Called when an impression occurs on the ad.
debugPrint('Ad recorded an impression.');
},
onAdClicked: (ad) {
// Called when a click is recorded for an ad.
debugPrint('Ad was clicked.');
},
);
顯示插頁式廣告
AdManagerInterstitialAd
會以 Overlay
形式顯示在所有應用程式內容上方,而且位置固定,因此無法加入 Flutter 小工具樹狀結構。您可以藉由呼叫 show()
來選擇何時顯示廣告。
_interstitialAd?.show();
呼叫 show()
後,以這種方式顯示的 Ad
無法以程式輔助關閉,必須由使用者操作才可以。AdManagerInterstitialAd
只能顯示一次,再次呼叫 show() 會觸發 onAdFailedToShowFullScreenContent
。
不再需要某則廣告時,請務必釋放相關資源。最佳做法是在 FullScreenContentCallback.onAdDismissedFullScreenContent
和 FullScreenContentCallback.onAdFailedToShowFullScreenContent
回呼中呼叫 dispose()
。
大功告成!您的應用程式已能順利顯示插頁式廣告。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-25 (世界標準時間)。
[null,null,["上次更新時間:2025-08-25 (世界標準時間)。"],[[["\u003cp\u003eInterstitial ads are full-screen ads displayed at natural transition points in an app, giving users the choice to interact or close them.\u003c/p\u003e\n"],["\u003cp\u003eAlways test with test ads during development to avoid account suspension, using the provided test ad unit ID \u003ccode\u003e/21775744923/example/interstitial\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLoad an interstitial ad using \u003ccode\u003eAdManagerInterstitialAd.load()\u003c/code\u003e and handle ad events with \u003ccode\u003eFullScreenContentCallback\u003c/code\u003e for lifecycle management.\u003c/p\u003e\n"],["\u003cp\u003eDisplay the ad using \u003ccode\u003e_interstitialAd.show()\u003c/code\u003e, noting it cannot be programmatically dismissed and should be disposed of properly after display.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/interstitial \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/interstitial \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/interstitial \"View this page for the Unity platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/interstitial \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nInterstitial ads are full-screen ads that cover the interface of their host app.\nThey're typically displayed at natural transition points in the flow of an app,\nsuch as between activities or during the pause between levels in a game. When an\napp shows an interstitial ad, the user has the choice to either tap on the ad\nand continue to its destination or close it and return to the app.\n\nThis guide explains how to integrate interstitial ads into a Flutter app.\n\nAlways test with test ads\n\nWhen building and testing your apps, make sure you use test ads rather than\nlive, production ads. Failure to do so can lead to suspension of your account.\n\nThe easiest way to load test ads is to use our dedicated test ad unit ID for\ninterstitials:\n\n- `/21775744923/example/interstitial`\n\nThe test ad units are configured to return test ads for every request, and\nyou're free to use them in your own apps while coding, testing, and debugging.\nJust make sure you replace them with your own ad unit IDs before publishing your\napp.\n\nLoad an ad\n\nThe following example loads an interstitial ad: \n\n InterstitialAd.load(\n adUnitId: \"\u003cvar translate=\"no\"\u003e_adUnitId\u003c/var\u003e\",\n request: const AdManagerAdRequest(),\n adLoadCallback: InterstitialAdLoadCallback(\n onAdLoaded: (InterstitialAd ad) {\n // Called when an ad is successfully received.\n debugPrint('Ad was loaded.');\n // Keep a reference to the ad so you can show it later.\n _interstitialAd = ad;\n },\n onAdFailedToLoad: (LoadAdError error) {\n // Called when an ad request failed.\n debugPrint('Ad failed to load with error: $error');\n },\n ),\n ); \n https://github.com/googleads/googleads-mobile-flutter/blob/9e63c9ad1459a7bbeeb9465ab3c6e25309f54683/packages/google_mobile_ads/example/lib/snippets/interstitial_ad_snippets.dart#L91-L109\n\nReplace \u003cvar translate=\"no\"\u003e_adUnitId\u003c/var\u003e with your own ad unit ID.\n\nInterstitial ad events\n\nThrough the use of `FullScreenContentCallback`, you can listen for lifecycle\nevents, such as when the ad is shown or dismissed. Set\n`AdManagerInterstitialAd.fullScreenContentCallback` before showing the ad to receive\nnotifications for these events. This example implements each method: \n\n ad.fullScreenContentCallback = FullScreenContentCallback(\n onAdShowedFullScreenContent: (ad) {\n // Called when the ad showed the full screen content.\n debugPrint('Ad showed full screen content.');\n },\n onAdFailedToShowFullScreenContent: (ad, err) {\n // Called when the ad failed to show full screen content.\n debugPrint('Ad failed to show full screen content with error: $err');\n // Dispose the ad here to free resources.\n ad.dispose();\n },\n onAdDismissedFullScreenContent: (ad) {\n // Called when the ad dismissed full screen content.\n debugPrint('Ad was dismissed.');\n // Dispose the ad here to free resources.\n ad.dispose();\n },\n onAdImpression: (ad) {\n // Called when an impression occurs on the ad.\n debugPrint('Ad recorded an impression.');\n },\n onAdClicked: (ad) {\n // Called when a click is recorded for an ad.\n debugPrint('Ad was clicked.');\n },\n ); \n https://github.com/googleads/googleads-mobile-flutter/blob/9e63c9ad1459a7bbeeb9465ab3c6e25309f54683/packages/google_mobile_ads/example/lib/snippets/interstitial_ad_snippets.dart#L56-L81\n\nDisplay an interstitial ad\n\nAn `AdManagerInterstitialAd` is displayed as an [`Overlay`](//api.flutter.dev/flutter/widgets/Overlay-class.html)\non top of all app content and is statically placed; thus, it can't be added to\nthe Flutter widget tree. You can choose when to show the ad by calling `show()`. \n\n _interstitialAd?.show(); \n https://github.com/googleads/googleads-mobile-flutter/blob/9e63c9ad1459a7bbeeb9465ab3c6e25309f54683/samples/admob/interstitial_example/lib/main.dart#L238-L238\n\nOnce `show()` is called, an `Ad` displayed this way can't be dismissed\nprogrammatically and requires user input. An `AdManagerInterstitialAd` can only be shown\nonce. Subsequent calls to show will trigger `onAdFailedToShowFullScreenContent`.\n\nAn ad must be disposed when access to it is no longer needed. The best practice\nfor when to call `dispose()` is in the\n`FullScreenContentCallback.onAdDismissedFullScreenContent` and\n`FullScreenContentCallback.onAdFailedToShowFullScreenContent` callbacks.\n\nThat's it! Your app is now ready to display interstitial ads.\n\nNext steps\n\n- See [Interstitial best\n practices](//www.youtube.com/watch?v=r2RgFD3Apyo&index=5&list=PLOU2XLYxmsIKX0pUJV3uqp6N3NeHwHh0c) and [interstitial ad guidance](//support.google.com/admob/answer/6066980).\n- Check out an [Interstitial ads case\n study](//admob.google.com/home/resources/freaking-math-powers-revenue-increase-with-google-admob-support/)."]]