تتيح إعدادات نمط الإعلانات المدمجة مع المحتوى لـ "مدير إعلانات Google" معالجة عرض إعلاناتك المدمجة مع المحتوى استنادًا إلى أنماط الإعلانات المدمجة مع المحتوى التي تحدّدها ضمن المنتج. أولاً، حدِّد الحجم والاستهداف.
بعد ذلك، أضِف HTML وCSS وJavaScript لتحديد الإعلانات المتجاوبة التي تعرض محتوى عالي الجودة على جميع الشاشات. لست بحاجة إلى تنفيذ أي عملية عرض، لأنّ "مدير إعلانات Google" يطبّق تلقائيًا نمط الإعلان الأصلي المناسب للموقع المقصود. يتم تنفيذ "الأنماط الأصلية" بالطريقة نفسها التي يتم بها تنفيذ "إعلانات البانر"،
باستخدام GAMBannerView. ويمكن استخدامها مع حجم إعلان ثابت يتم تحديده مسبقًا، أو حجم إعلان مرن يتم تحديده في وقت التشغيل.
المتطلبات الأساسية
الإصدار 7.14.0 أو إصدار أحدث من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"
يفترض هذا الدليل معرفة عملية بحزمة "SDK لإعلانات Google على الأجهزة الجوّالة".
إذا لم يسبق لك إجراء ذلك، ننصحك بالاطّلاع على دليل البدء.
حجم ثابت
تتيح لك أنماط الإعلانات المدمجة مع المحتوى ذات الحجم الثابت التحكّم في عرض وارتفاع الإعلان المدمج مع المحتوى. لضبط حجم ثابت، اتّبِع الخطوات التالية:
أنشئ عنصرًا في واجهة مستخدم "مدير الإعلانات" واختَر أحد الأحجام المحدّدة مسبقًا من القائمة المنسدلة في الحقل Size.
في Interface Builder، اضبط عرض وارتفاع GAMBannerView
ليتطابقا مع الحجم المحدّد مسبقًا الذي اخترته في الخطوة 1. يمكنك الاطّلاع على قائمة بالأحجام وثوابتها المقابلة في قسم حجم البانر.GADAdSize
إنّ تنفيذ الأنماط المدمجة مع المحتوى بحجم ثابت بسيط مثل اتّباع التعليمات الواردة في طلب البانر الأول، ولكنّك تحصل على المرونة والتحكّم في HTML وCSS وJavaScript لمنح إعلان البانر مظهرًا مدمجًا مع المحتوى يبدو طبيعيًا في تطبيقك.
حجم السائل
في بعض الحالات، قد لا يكون الحجم الثابت مناسبًا. على سبيل المثال، قد تريد أن يتطابق عرض الإعلان مع محتوى تطبيقك، ولكن تحتاج إلى تعديل ارتفاعه بشكل ديناميكي ليتناسب مع محتوى الإعلان. للتعامل مع هذه الحالة، يمكنك تحديد Fluid كحجم الإعلان في واجهة مستخدم "إدارة الإعلانات"، ما يشير إلى أنّه يتم تحديد حجم الإعلان في وقت التشغيل في التطبيق. توفّر حزمة تطوير البرامج (SDK) الثابت الخاص GADAdSize، kGADAdSizeFluid، للتعامل مع هذه الحالة. يتم تحديد ارتفاع حجم الإعلان المرن بشكل ديناميكي استنادًا إلى العرض الذي يحدّده الناشر، ما يتيح GAMBannerView تعديل ارتفاعه ليتطابق مع ارتفاع تصميم الإعلان.
طلب سلس
على عكس أشكال الإعلانات الأخرى، لا يتضمّن حجم الإعلان kGADAdSizeFluid عرضًا محدّدًا مسبقًا، لذا احرص على ضبط عرض إطار البانر بشكل صريح في الرمز البرمجي أو في Interface Builder. في حال عدم تحديد عرض، تضبط حزمة تطوير البرامج (SDK) تلقائيًا ارتفاع البانر استنادًا إلى العرض الكامل للجهاز.
في حال تقديم طلب متعدد الأحجام يتضمّن kGADAdSizeFluid، سيتم دائمًا وضع الإعلان المعروض داخل حاوية مرنة وسيتصرف كإعلان مرن. في حال عرض تصميم إعلان غير مرن في هذه الحاوية المرنة، ستعمل حزمة SDK على توسيط الإعلان في الحاوية، وبالتالي لن تحتاج إلى تعديل قيود العرض في كل مرة يتم فيها عرض إعلان جديد.
إنّ عملية تنفيذ طلب مرن بحجم واحد وطلب مرن بأحجام متعددة متشابهة جدًا، والفرق الوحيد هو أنّه في طلب مرن بأحجام متعددة، عليك ضبط السمة validAdSizes لتحديد أحجام الإعلانات الصالحة لطلب الإعلان:
varbannerView:AdManagerBannerView!overridefuncviewDidLoad(){super.viewDidLoad()// Create the GAMBannerView and set its width to a width that makes sense for your// app. In this example, the width is set to the width of the UIViewController's// root view.bannerView=AdManagerBannerView(adSize:AdSizeFluid)varframeRect=bannerView.frameframeRect.size.width=view.bounds.widthbannerView.frame=frameRect// Uncomment this code for a multisize fluid request.// bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]bannerView.adUnitID="YOUR_AD_UNIT_ID"bannerView.rootViewController=self// Make the ad request.bannerView.load(AdManagerRequest())}
Objective-C
GAMBannerView*_bannerView;-(void)viewDidLoad{[superviewDidLoad];// Create the GAMBannerView and set its width to a width that makes sense for your// app. In this example, the width is set to the width of the UIViewController's// root view._bannerView=[[GAMBannerViewalloc]initWithAdSize:kGADAdSizeFluid];CGRectframeRect=_bannerView.frame;frameRect.size.width=CGRectGetWidth(self.view.bounds);_bannerView.frame=frameRect;// Uncomment this code for a multisize fluid request.// _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),// NSValueFromGADAdSize(kGADAdSizeBanner) ];_bannerView.adUnitID=@"YOUR_AD_UNIT_ID";_bannerView.rootViewController=self;// Make the ad request.[_bannerViewloadRequest:[GAMRequestrequest]];}
للاطّلاع على مثال على تنفيذ حجم الإعلان المرن في "مدير إعلانات Google"، نزِّل تطبيق iOS API Demo بلغة Swift أو Objective-C.
قد تحتاج إلى معرفة ارتفاع بانر قبل تغيير حجم إعلانه.
يُرسِل adView:willChangeAdSizeTo: إشعارًا إلى العنصر المفوض قبل أن يتغيّر عرض البانر إلى GADAdSize الجديد. لتلقّي إشعار قبل أن يتغيّر عرض البانر إلى حجم الإعلان الجديد، يجب أن يتوافق صفك مع البروتوكول GADAdSizeDelegate.
في ما يلي نموذج لتنفيذ دالة adView:willChangeAdSizeTo:
الردّ الذي يوضّح كيفية الحصول على العرض والارتفاع الجديدَين للبانر:
Swift
// To be notified before the banner's ad size changes, your view controller class must// conform to the GADAdSizeDelegate protocol.bannerView.adSizeDelegate=self// MARK: - GADAdSizeDelegatefuncadView(_bannerView:BannerView,willChangeAdSizeToadSize:AdSize){letheight=adSize.size.heightletwidth=adSize.size.width}
Objective-C
// To be notified before the banner's ad size changes, your view controller class must// conform to the GADAdSizeDelegate protocol._bannerView.adSizeDelegate=self;
#pragmamark-GADAdSizeDelegate-(void)adView:(GADBannerView*)bannerViewwillChangeAdSizeTo:(GADAdSize)adSize{CGFloatheight=adSize.size.height;CGFloatwidth=adSize.size.width;}
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eNative Styles in Google Ad Manager allow you to customize the look and feel of native ads using HTML, CSS, and JavaScript, rendering them seamlessly within your app.\u003c/p\u003e\n"],["\u003cp\u003eYou can define fixed-size native ads by specifying their dimensions in Ad Manager and your app's layout, similar to implementing banner ads.\u003c/p\u003e\n"],["\u003cp\u003eFluid-size native ads adjust their height dynamically based on content and available width, requiring you to set the desired width in your app's code.\u003c/p\u003e\n"],["\u003cp\u003eTo get notified before a banner's size changes (especially useful for fluid ads), implement the \u003ccode\u003eGADAdSizeDelegate\u003c/code\u003e protocol and its \u003ccode\u003eadView:willChangeAdSizeTo:\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eYou can download the iOS API Demo app for example implementations of Native Styles, including fluid ad sizes.\u003c/p\u003e\n"]]],["Native styles in Google Ad Manager utilize HTML, CSS, and JavaScript for ad rendering. Ad size can be fixed by setting predefined dimensions in the UI and `GAMBannerView`, or fluid, adjusting dynamically at runtime with `kGADAdSizeFluid`. Fluid ads require setting the banner's frame width. Multisize requests can include fluid and other ad sizes. `GADAdSizeDelegate` enables notification before banner size changes, providing access to the new width and height.\n"],null,["# Native Styles\n\nSelect platform: [Android](/ad-manager/mobile-ads-sdk/android/native/styles \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/native/styles \"View this page for the iOS platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/native/styles \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\n| **Note:** Native Styles use HTML and CSS that you configure in Google Ad Manager. If you're looking to render your own in-app ads using native objects, please see [Native Advanced](/ad-manager/mobile-ads-sdk/ios/native/advanced).\n\n[Native style settings](//support.google.com/admanager/answer/6366914)\nenable Google Ad Manager to handle the rendering of your native ads based on native\nstyles you specify within the product. First, specify size and targeting.\nThen add HTML, CSS, and JavaScript to define ads that are responsive\nand produce a quality display across all screens. You don't need to do\nany of the rendering; Ad Manager automatically applies the right native style\nfor the destination. Native styles are implemented just like banner ads,\nusing a `GAMBannerView`. They can be used with a fixed ad\nsize determined ahead of time, or a fluid ad size determined at runtime.\n\nPrerequisites\n-------------\n\n- Google Mobile Ads SDK version 7.14.0 or higher\n\nThis guide assumes some working knowledge of the Google Mobile Ads SDK.\nIf you haven't already done so, consider running through our\n[Get Started](/ad-manager/mobile-ads-sdk/ios/quick-start) guide.\n\nFixed size\n----------\n\nNative styles with a fixed size allow you to control the width and height\nof the native ad. To set a fixed size, follow these steps:\n\n1. Create a line item in the Ad Manager UI and select one of the\n predefined sizes from the `Size` field dropdown.\n\n2. In Interface Builder, set the width and height of the `GAMBannerView`\n to match the predefined size you selected in step 1. You can see a\n list of sizes and their corresponding `GADAdSize` constants in the [Banner\n size](/ad-manager/mobile-ads-sdk/ios/banner#banner_size)\n section.\n\nImplementing native styles with a fixed size is as simple as following\nthe instructions in [Your first banner\nrequest](/ad-manager/mobile-ads-sdk/ios/quick-start#your_first_banner_request),\nbut you gain the flexibility and control over the HTML, CSS, and JavaScript\nto give your banner ad a native look and feel that's natural in your app.\n\nFluid size\n----------\n\nIn some cases, a fixed size may not make sense. For example, you may\nwant the width of the ad to match your app's content, but need its height\nto dynamically adjust to fit the ad's content. To handle this case,\nyou can specify `Fluid` as the ad size in the Ad Manager UI, which\ndesignates that the size of the ad is determined at runtime in the app.\nThe SDK provides a special `GADAdSize` constant,\n[`kGADAdSizeFluid`](/ad-manager/mobile-ads-sdk/ios/api/reference/Constants#/c:@kGADAdSizeFluid),\nto handle this case. The fluid ad size height is dynamically determined\nbased on the publisher defined width, allowing the\n[`GAMBannerView`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GAMBannerView),\nto adjust its height to match that of the creative.\n\n### Fluid request\n\nUnlike other ad formats, the `kGADAdSizeFluid` ad size does not have\na predefined width, so make sure to explicitly set the banner's frame\nwidth in your code or in Interface Builder. If a width is not specified,\nthe SDK by default sets the height of the banner based on the full\nwidth of the device.\n\nIf you make a multisize request that includes `kGADAdSizeFluid`,\nthe ad returned is always placed inside a fluid container and\nbehave like a fluid ad. In the event that a non-fluid creative is\nreturned in this fluid container, the SDK centers the ad in the\ncontainer so that you don't have to modify the width constraint\neach time a new ad is returned.\n\nThe implementation for making a single size and a multisize fluid\nrequest is very similar; the only difference is for a multisize\nrequest, you set the `validAdSizes` property to specify the ad\nsizes that are valid for the ad request: \n\n### Swift\n\n bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]\n\n### Objective-C\n\n _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),\n NSValueFromGADAdSize(kGADAdSizeBanner) ];\n\nHere's what the full implementation looks like in code: \n\n### Swift\n\n var bannerView: AdManagerBannerView!\n\n override func viewDidLoad() {\n super.viewDidLoad()\n // Create the GAMBannerView and set its width to a width that makes sense for your\n // app. In this example, the width is set to the width of the UIViewController's\n // root view.\n bannerView = AdManagerBannerView(adSize: AdSizeFluid)\n var frameRect = bannerView.frame\n frameRect.size.width = view.bounds.width\n bannerView.frame = frameRect\n\n // Uncomment this code for a multisize fluid request.\n // bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]\n\n bannerView.adUnitID = \"YOUR_AD_UNIT_ID\"\n bannerView.rootViewController = self\n\n // Make the ad request.\n bannerView.load(AdManagerRequest())\n }\n\n### Objective-C\n\n GAMBannerView *_bannerView;\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n // Create the GAMBannerView and set its width to a width that makes sense for your\n // app. In this example, the width is set to the width of the UIViewController's\n // root view.\n _bannerView = [[GAMBannerView alloc] initWithAdSize:kGADAdSizeFluid];\n CGRect frameRect = _bannerView.frame;\n frameRect.size.width = CGRectGetWidth(self.view.bounds);\n _bannerView.frame = frameRect;\n\n // Uncomment this code for a multisize fluid request.\n // _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),\n // NSValueFromGADAdSize(kGADAdSizeBanner) ];\n\n _bannerView.adUnitID = @\"YOUR_AD_UNIT_ID\";\n _bannerView.rootViewController = self;\n\n // Make the ad request.\n [_bannerView loadRequest:[GAMRequest request]];\n }\n\nTo see an example implementation of the Ad Manager Fluid ad size,\ndownload the iOS API Demo app in Swift or Objective-C.\n\n[Download API Demo](//github.com/googleads/googleads-mobile-ios-examples/releases/latest)\n\nGADAdSizeDelegate protocol\n--------------------------\n\nYou may want to know the height of a banner before its ad size changes.\nThe `adView:willChangeAdSizeTo:` callback notifies its delegate before\nthe banner view changes to the new `GADAdSize`. To be notified before\nthe banner view changes to the new ad size, your class must conform to\nthe `GADAdSizeDelegate` protocol.\n\nHere's a sample implementation of the `adView:willChangeAdSizeTo:`\ncallback that shows how to get the new width and height of the banner: \n\n### Swift\n\n // To be notified before the banner's ad size changes, your view controller class must\n // conform to the GADAdSizeDelegate protocol.\n bannerView.adSizeDelegate = self\n\n // MARK: - GADAdSizeDelegate\n\n func adView(_ bannerView: BannerView, willChangeAdSizeTo adSize: AdSize) {\n let height = adSize.size.height\n let width = adSize.size.width\n }\n\n### Objective-C\n\n // To be notified before the banner's ad size changes, your view controller class must\n // conform to the GADAdSizeDelegate protocol.\n _bannerView.adSizeDelegate = self;\n\n #pragma mark - GADAdSizeDelegate\n\n - (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize {\n CGFloat height = adSize.size.height;\n CGFloat width = adSize.size.width;\n }"]]