Banner ads occupy a spot within an app's layout, either at the top or bottom of the device screen. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time.
این راهنما به شما کمک میکند تا با تبلیغات بنری تطبیقی لنگری شروع کنید. بنرهای تطبیقی لنگری، اندازه تبلیغ را برای هر دستگاه با استفاده از عرض تبلیغی که شما مشخص میکنید، بهینه میکنند.
Anchored adaptive banner ads are fixed aspect ratio ads rather than fixed size ads. The aspect ratio is similar to 320x50. Once you specify the full width available, Google Mobile Ads SDK returns an ad with optimal height for that width. The optimal height for the ad remains constant across different ad requests, and the content surrounding the ad stays in place when the ad refreshes.
همیشه با تبلیغات آزمایشی تست کنید
هنگام ساخت و آزمایش برنامههای خود، مطمئن شوید که از تبلیغات آزمایشی به جای تبلیغات زنده و تولیدی استفاده میکنید. عدم انجام این کار میتواند منجر به مسدود شدن حساب شما شود.
سادهترین راه برای بارگذاری تبلیغات آزمایشی، استفاده از شناسه اختصاصی واحد تبلیغات آزمایشی ما برای بنرها است:
/21775744923/example/adaptive-banner
واحدهای تبلیغاتی آزمایشی طوری پیکربندی شدهاند که برای هر درخواست، تبلیغات آزمایشی را برگردانند و شما میتوانید هنگام کدنویسی، آزمایش و اشکالزدایی از آنها در برنامههای خود استفاده کنید. فقط قبل از انتشار برنامه، مطمئن شوید که آنها را با شناسههای واحدهای تبلیغاتی خود جایگزین میکنید.
اندازه تبلیغ را دریافت کنید
برای درخواست بنر تبلیغاتی با اندازه صحیح، مراحل زیر را دنبال کنید:
با استفاده از
MediaQuery.of(context)عرض صفحه نمایش دستگاه را بر حسب پیکسلهای مستقل از چگالی (dp) دریافت کنید. اگر نمیخواهید از عرض کامل صفحه استفاده کنید، میتوانید عرض دلخواه خود را تنظیم کنید.Use the appropriate static method on the
AdSizeclass to get anAdSizeobject. For example, useAdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(int width)to get the ad size for the current orientation.
// Get an AnchoredAdaptiveBannerAdSize before loading the ad.
final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
MediaQuery.sizeOf(context).width.truncate(),
);
بارگذاری یک تبلیغ
مثال زیر یک بنر تبلیغاتی را بارگذاری میکند:
به جای _adUnitId ، شناسه واحد تبلیغاتی خودتان را قرار دهید.
رویدادهای تبلیغات بنری
با استفاده از AdManagerBannerAdListener ، میتوانید به رویدادهای چرخه عمر، مانند زمان بارگذاری یک تبلیغ، گوش دهید. این مثال هر متد را پیادهسازی کرده و پیامی را در کنسول ثبت میکند:
onAdOpened: (Ad ad) {
// Called when an ad opens an overlay that covers the screen.
debugPrint("Ad was opened.");
},
onAdClosed: (Ad ad) {
// Called when an ad removes an overlay that covers the screen.
debugPrint("Ad was closed.");
},
onAdImpression: (Ad ad) {
// Called when an impression occurs on the ad.
debugPrint("Ad recorded an impression.");
},
onAdClicked: (Ad ad) {
// Called when an a click event occurs on the ad.
debugPrint("Ad was clicked.");
},
onAdWillDismissScreen: (Ad ad) {
// iOS only. Called before dismissing a full screen view.
debugPrint("Ad will be dismissed.");
},
تازه کردن یک آگهی
If you configured your ad unit to refresh, you don't need to request another ad when the ad fails to load. Google Mobile Ads SDK respects any refresh rate you specified in the Ad Manager UI. If you haven't enabled refresh, issue a new request. For more details on ad unit refresh, such as setting a refresh rate, see Refresh rate for ads in mobile apps .
نمایش بنر تبلیغاتی
To display a AdManagerBannerAd as a widget, you must instantiate an AdWidget with a supported ad after calling load() . You can create the widget before calling load() , but load() must be called before adding it to the widget tree.
AdWidget inherits from Flutter's Widget class and can be used like any other widget. On iOS, make sure you place the widget in a widget with a specified width and height. Otherwise, your ad may not be displayed. A AdManagerBannerAd can be placed in a container with a size that matches the ad:
if (_bannerAd != null)
Align(
alignment: Alignment.bottomCenter,
child: SafeArea(
child: SizedBox(
width: _bannerAd!.size.width.toDouble(),
height: _bannerAd!.size.height.toDouble(),
child: AdWidget(ad: _bannerAd!),
),
),
),
An ad must be disposed when access to it is no longer needed. The best practice for when to call dispose() is either after the AdWidget is removed from the widget tree or in the AdManagerBannerAdListener.onAdFailedToLoad() callback.
تمام! برنامه شما اکنون آماده نمایش تبلیغات بنری است.
محدودیت پیمایش در اندروید ۹ و پایینتر
We are aware that some older or less powerful devices running Android 9 or earlier may have suboptimal performance when displaying inline banner ads within scrolling views. We recommend only using these types of banners on Android 10 or later. Fixed position banners such as anchored banners are not affected and can be used with optimal performance on all Android API levels.
آشنایی با انواع دیگر بنر
با انواع دیگر بنرهای تعریف شده در این بخش برای برنامه Flutter خود آشنا شوید.
بنرهای تطبیقی درون خطی
Inline adaptive banners have variable height and are larger, taller banners compared to anchored adaptive banners. Inline adaptive banners are recommended over anchored adaptive banner ads for apps that place banner ads in scrollable content. For more details, see inline adaptive banners .
بنرهای تاشو
Collapsible banner ads are banner ads that are initially presented as a larger overlay, with a button to collapse the ad to a smaller size. Consider using this banner to further optimize your performance. For more details, see collapsible banner ads .