Google Mobile Ads SDK תומך בגדלים קבועים של מודעות למקרים שבהם מודעות באנר מותאמות לא עונות על הצרכים שלכם.
בטבלה הבאה מפורטים הגדלים הסטנדרטיים של באנרים.
גודל ב-dp (רוחבxגובה) | תיאור | זמינות | הקבוע AdSize |
---|---|---|---|
320x50 | מודעת באנר | טלפונים וטאבלטים | GADAdSizeBanner |
320x100 | מודעת באנר גדולה | טלפונים וטאבלטים | GADAdSizeLargeBanner |
300x250 | מלבן בינוני של IAB | טלפונים וטאבלטים | GADAdSizeMediumRectangle |
468x60 | מודעת באנר בגודל מלא של IAB | טאבלטים | GADAdSizeFullBanner |
728x90 | טבלת הבאז של IAB | טאבלטים | GADAdSizeLeaderboard |
כדי להגדיר גודל באנר מותאם אישית, מגדירים את הגודל באמצעות GADAdSizeFromCGSize
:
Swift
let adSize = adSizeFor(cgSize: CGSize(width: 250, height: 250))
Objective-C
GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));
דוגמה למודעות באנר בגודל קבוע
גודל מודעה בהתאמה אישית
בנוסף ליחידות המודעות הרגילות, ב-Google Ad Manager אפשר להציג באפליקציה יחידות מודעות בכל גודל. הגודל של המודעה (רוחב, גובה) שמוגדר בבקשה להצגת מודעה צריך להיות זהה לממדים של תצוגת המודעה (GAMBannerView
) שמוצגת באפליקציה. כדי להגדיר גודל מותאם אישית, משתמשים ב-GADAdSizeFromCGSize
.
Swift
// Define custom GADAdSize of 250x250 for GAMBannerView.
let customAdSize = adSizeFor(cgSize: CGSize(width: 250, height: 250))
bannerView = GAMBannerView(adSize: customAdSize)
Objective-C
// Define custom GADAdSize of 250x250 for GAMBannerView
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
self.bannerView = [[GAMBannerView alloc] initWithAdSize:customAdSize];
כמה גדלים של מודעות
ב-Ad Manager אפשר לציין כמה גדלים של מודעות שיכולות להיות כשירות להצגה בGAMBannerView
. כדי להשתמש בתכונה הזו, צריך לבצע שלושה שלבים:
בממשק המשתמש של Ad Manager, יוצרים פריט שמטרגט את אותה יחידת מודעות שמקושרת לקריאייטיבים בגדלים שונים.
באפליקציה, מגדירים את המאפיין
validAdSizes
ב-GAMBannerView
:Swift
// Define an optional array of GADAdSize to specify all valid sizes that are appropriate // for this slot. Never create your own GADAdSize directly. Use one of the // predefined standard ad sizes (such as GADAdSizeBanner), or create one using // the GADAdSizeFromCGSize method. // // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note // that all desired sizes should be included in the validAdSizes array. bannerView.validAdSizes = [NSValueFromGADAdSize(AdSizeBanner), NSValueFromGADAdSize(AdSizeMediumRectangle), NSValueFromGADAdSize(adSizeFor(cgSize: CGSize(width: 120, height: 20)))]
Objective-C
// Define an optional array of GADAdSize to specify all valid sizes that are appropriate // for this slot. Never create your own GADAdSize directly. Use one of the // predefined standard ad sizes (such as GADAdSizeBanner), or create one using // the GADAdSizeFromCGSize method. // // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note // that all desired sizes should be included in the validAdSizes array. self.bannerView.validAdSizes = @[ NSValueFromGADAdSize(GADAdSizeBanner), NSValueFromGADAdSize(GADAdSizeMediumRectangle), NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSizeMake(120, 20))) ];
מטמיעים את השיטה
GADAdSizeDelegate
כדי לזהות שינוי בגודל המודעה.Swift
public func bannerView(_ bannerView: BannerView, willChangeAdSizeTo size: AdSize)
Objective-C
- (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
חשוב להגדיר את הנציג לפני ששולחים בקשה להצגת מודעה.
Swift
bannerView.adSizeDelegate = self
Objective-C
self.bannerView.adSizeDelegate = self;