الإعلانات على شاشة فتح التطبيق

هذا الدليل مخصَّص للناشرين الذين يدمجون الإعلانات على شاشة فتح التطبيق.

الإعلانات على شاشة فتح التطبيق هي شكل خاص من أشكال الإعلانات مصمّمة للناشرين الذين يريدون تحقيق الربح. شاشات تحميل تطبيقاتهم. يمكن للمستخدمين إغلاق الإعلانات على شاشة فتح التطبيق في أي وقت. يمكن عرض "الإعلانات على شاشة فتح التطبيق" عندما يعرض المستخدمون تطبيقك إلى المقدّمة.

تعرض "الإعلانات على شاشة فتح التطبيق" تلقائيًا مساحة صغيرة خاصة بالعناصر البصرية للعلامة التجارية كي يعرف المستخدمون أنّهم داخل التطبيق تطبيقك. في ما يلي مثال على الشكل الذي يظهر به الإعلان على شاشة فتح التطبيق:

إليك الخطوات المطلوبة لتنفيذ الإعلانات على شاشة فتح التطبيق، وذلك على مستوى عالٍ:

  1. أنشئ فئة إدارية تحمِّل إعلانًا قبل الحاجة إلى عرضه.
  2. يمكنك عرض الإضافة أثناء الأحداث التي تعمل في المقدّمة.
  3. التعامل مع طلبات معاودة الاتصال بالعروض التقديمية.

المتطلبات الأساسية

الاختبار دائمًا باستخدام الإعلانات الاختبارية

عند إنشاء تطبيقاتك واختبارها، احرص على استخدام إعلانات تجريبية بدلاً من إعلانات بث مباشر وقد يؤدي عدم الالتزام بذلك إلى تعليق حسابك.

أسهل طريقة لتحميل الإعلانات الاختبارية هي استخدام رقم التعريف المخصّص للوحدة الإعلانية الاختبارية للتطبيق فتح الإعلانات:

ca-app-pub-3940256099942544/5575463023

لقد تم إعدادها خصيصًا لعرض إعلانات اختبارية لكل طلب، يمكنك استخدامها مجانًا في تطبيقاتك الخاصة أثناء الترميز والاختبار وتصحيح الأخطاء. ما عليك سوى إجراء واحرص على استبداله بمعرّف وحدتك الإعلانية قبل نشر تطبيقك.

لمزيد من المعلومات عن آلية عمل الإعلانات الاختبارية لحزمة تطوير البرامج (SDK) لعرض الإعلانات للأجهزة الجوّالة، راجع اختبار الإعلانات:

تنفيذ صف دراسي

يجب أن يظهر إعلانك بسرعة، لذلك من الأفضل تحميل إعلانك قبل أن تحتاج إلى لعرضها. بهذه الطريقة، سيكون لديك إعلان جاهز للعرض بعد دخول المستخدم تطبيقك. نفِّذ صفًا إداريًا لتقديم طلبات الإعلانات مسبقًا عند الحاجة لعرض الإعلان.

أنشِئ فئة فردية جديدة باسم "AppOpenAdManager" واملأها باسم التالي:

Swift

class AppOpenAdManager: NSObject {
  var appOpenAd: GADAppOpenAd?
  var isLoadingAd = false.
  var isShowingAd = false

  static let shared = AppOpenAdManager()

  private func loadAd() async {
    // TODO: Implement loading an ad.
  }

  func showAdIfAvailable() {
    // TODO: Implement showing an ad.
  }

  private func isAdAvailable() -> Bool {
    // Check if ad exists and can be shown.
    return appOpenAd != nil
  }
}

Objective-C

@interface AppOpenAdManager ()
@property(nonatomic, strong) GADAppOpenAd *appOpenAd;
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;

@end

@implementation AppOpenAdManager

+ (nonnull AppOpenAdManager *)sharedInstance {
  static AppOpenAdManager *instance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    instance = [[AppOpenAdManager alloc] init];
  });
  return instance;
}

- (void)loadAd {
  // TODO: Implement loading an ad.
}

// Add this method to the .h file.
- (void)showAdIfAvailable {
  // TODO: Implement showing an ad.
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil;
}

@end

تحميل إعلان

الخطوة التالية هي ملء طريقة loadAd().

Swift

private func loadAd() async {
  // Do not load ad if there is an unused ad or one is already loading.
  if isLoadingAd || isAdAvailable() {
    return
  }
  isLoadingAd = true

  do {
    appOpenAd = try await GADAppOpenAd.load(
      withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
  } catch {
    print("App open ad failed to load with error: \(error.localizedDescription)")
  }
  isLoadingAd = false
}

Objective-C

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    return;
  }
  self.isLoadingAd = YES;

  [GADAppOpenAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/5575463023"
                       request:[GADRequest request]
             completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) {
               self.isLoadingAd = NO;
               if (error) {
                 NSLog(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
             }];
}

عرض إعلان

الخطوة التالية هي ملء طريقة showAdIfAvailable(). إذا لم يتم عرض إعلان المتوفرة، تحاول الطريقة تحميل إعلان.

Swift

func showAdIfAvailable() {
  // If the app open ad is already showing, do not show the ad again.
  guard !isShowingAd else { return }

  // If the app open ad is not available yet but is supposed to show, load
  // a new ad.
  if !isAdAvailable() {
    Task {
      await loadAd()
    }
    return
  }

  if let ad = appOpenAd {
    isShowingAd = true
    ad.present(fromRootViewController: nil)
  }
}

Objective-C

- (void)showAdIfAvailable {
  // If the app open ad is already showing, do not show the ad again.
  if (self.isShowingAd) {
    return;
  }

  // If the app open ad is not available yet but is supposed to show, load a
  // new ad.
  if (![self isAdAvailable]) {
    [self loadAd];
    return;
  }

  self.isShowingAd = YES;
  [self.appOpenAd presentFromRootViewController:nil];
}

عرض الإعلان أثناء الأحداث التي تعمل في المقدّمة

عندما يصبح التطبيق نشطًا، يمكنك الاتصال بالرقم showAdIfAvailable() لعرض إعلان في حال توفر إحداها أو تحمّل علامة جديدة.

Swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  // ...

  func applicationDidBecomeActive(_ application: UIApplication) {
    // Show the app open ad when the app is foregrounded.
    AppOpenAdManager.shared.showAdIfAvailable()
  }
}

Objective-C

@implementation AppDelegate
// ...

- (void) applicationDidBecomeActive:(UIApplication *)application {
  // Show the app open ad when the app is foregrounded.
  [AppOpenAdManager.sharedInstance showAdIfAvailable];
}

@end

التعامل مع طلبات معاودة الاتصال بالعرض التقديمي

عندما يعرض تطبيقك إعلانًا على شاشة فتح التطبيق، عليك الاعتماد على GADFullScreenContentDelegate للتعامل مع أحداث عروض تقديمية معينة. ضِمن عليك تحديدًا طلب الإعلان التالي على شاشة فتح التطبيق بعد ينتهي من التقديم.

في صف AppOpenAdManager، أضِف ما يلي:

Swift

class AppOpenAdManager: NSObject, GADFullScreenContentDelegate {
  // ...

  private func loadAd() async {
    // Do not load ad if there is an unused ad or one is already loading.
    if isLoadingAd || isAdAvailable() {
      return
    }
    isLoadingAd = true

    do {
      appOpenAd = try await GADAppOpenAd.load(
        withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
      appOpenAd?.fullScreenContentDelegate = self
    } catch {
      print("App open ad failed to load with error: \(error.localizedDescription)")
    }
    isLoadingAd = false
  }

  // ...

  // MARK: - GADFullScreenContentDelegate methods

  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("App open ad will be presented.")
  }

  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    appOpenAd = nil
    isShowingAd = false
    // Reload an ad.
    Task {
      await loadAd()
    }
  }

  func ad(
    _ ad: GADFullScreenPresentingAd,
    didFailToPresentFullScreenContentWithError error: Error
  ) {
    appOpenAd = nil
    isShowingAd = false
    // Reload an ad.
    Task {
      await loadAd()
    }
  }
}

Objective-C

@interface AppOpenAdManager () <GADFullScreenContentDelegate>
@property(nonatomic, strong) GADAppOpenAd *appOpenAd
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;

@end

@implementation AppOpenAdManager

// ...

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    return;
  }
  self.isLoadingAd = YES;

  [GADAppOpenAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/5575463023"
                       request:[GADRequest request]
             completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) {
              self.isLoadingAd = NO;
               if (error) {
                 NSLog(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
               self.appOpenAd.fullScreenContentDelegate = self;
             }];
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil;
}

// ...

#pragma mark - GADFullScreenContentDelegate methods

- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad is will be presented.");
}

- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  // Reload an ad.
  [self loadAd];
}

- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
    didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  // Reload an ad.
  [self loadAd];
}

@end

مراعاة انتهاء صلاحية الإعلان

لضمان عدم عرض إعلان منتهي الصلاحية، يمكنك إضافة طريقة إلى التفويض باستخدام التطبيق يتحقّق من الوقت المنقضي منذ تحميل مرجع إعلانك.

في AppOpenAdManager، أضِف السمة Date باسم loadTime واضبط الموقع عند تحميل الإعلان. ويمكنك بعد ذلك إضافة طريقة تُرجع true إذا مرور أقل من عدد معين من الساعات منذ تحميل إعلانك. يُرجى التأكد من أنّ: عليك التحقّق من صلاحية مرجع إعلانك قبل محاولة عرض الإعلان.

Swift

class AppOpenAdManager: NSObject, GADFullScreenContentDelegate {
  var appOpenAd: GADAppOpenAd?
  var isLoadingAd = false.
  var isShowingAd = false
  var loadTime: Date?
  let fourHoursInSeconds = TimeInterval(3600 * 4)

  // ...

  private func loadAd() async {
    // Do not load ad if there is an unused ad or one is already loading.
    if isLoadingAd || isAdAvailable() {
      return
    }
    isLoadingAd = true

    do {
      appOpenAd = try await GADAppOpenAd.load(
        withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
      appOpenAd?.fullScreenContentDelegate = self
      loadTime = Date()
    } catch {
      print("App open ad failed to load with error: \(error.localizedDescription)")
    }
    isLoadingAd = false
  }

  private func wasLoadTimeLessThanFourHoursAgo() -> Bool {
    guard let loadTime = loadTime else { return false }
    // Check if ad was loaded more than four hours ago.
    return Date().timeIntervalSince(loadTime) < fourHoursInSeconds
  }

  private func isAdAvailable() -> Bool {
    // Check if ad exists and can be shown.
    return appOpenAd != nil && wasLoadTimeLessThanFourHoursAgo()
  }
}

Objective-C

static NSTimeInterval const fourHoursInSeconds = 3600 * 4;

@interface AppOpenAdManager () <GADFullScreenContentDelegate>
@property(nonatomic, strong) GADAppOpenAd *appOpenAd
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;
@property(weak, nonatomic) NSDate *loadTime;

@end

@implementation AppOpenAdManager

// ...

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    return;
  }
  self.isLoadingAd = YES;

  [GADAppOpenAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/5575463023"
                       request:[GADRequest request]
             completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) {
              self.isLoadingAd = NO;
               if (error) {
                 NSLog(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
               self.appOpenAd.fullScreenContentDelegate = self;
               self.loadTime = [NSDate date];
             }];
}

- (BOOL)wasLoadTimeLessThanFourHoursAgo {
  // Check if ad was loaded more than four hours ago.
  return [[NSDate Date] timeIntervalSinceDate:self.loadTime] < fourHoursInSeconds;
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil && [self wasLoadTimeLessThanFourHoursAgo];
}

@end

شاشات التشغيل على البارد وشاشة التحميل

تفترض المستندات أنّك لا تعرض الإعلانات على شاشة فتح التطبيق إلا عندما ينفِّذ المستخدمون تقديم تطبيقك في المقدّمة عند تعليقه في الذاكرة "بداية باردة" تحدث عندما إطلاق تطبيقك ولكنه لم يسبق تعليقه في الذاكرة.

مثال على التشغيل على البارد هو عندما يفتح المستخدم تطبيقك لأول مرة. مع التشغيل على البارد، لن يكون لديك إعلان على شاشة فتح التطبيق تم تحميله مسبقًا وجاهز ستظهر على الفور. التأخير بين وقت طلب إعلان واستلامه الرجوع إلى حالة يمكن فيها للمستخدمين استخدام تطبيقك لفترة وجيزة قبل المفاجأة بإعلان خارج السياق. ينبغي تجنب ذلك لأنه تجربة مستخدم سيئة.

إنّ الطريقة المفضّلة لاستخدام الإعلانات على شاشة فتح التطبيق عند التشغيل على البارد هي استخدام شاشة تحميل. لتحميل مواد عرض ألعابك أو تطبيقاتك، ولعرض الإعلان فقط من صفحة التحميل الشاشة. إذا اكتمل تحميل تطبيقك وأرسل المستخدم إلى صفحة لمحتوى تطبيقك، فلا تعرض الإعلان.

أفضل الممارسات

أنشأت Google الإعلانات على شاشة فتح التطبيق لمساعدتك في تحقيق الربح من شاشة تحميل تطبيقك، ولكن من المهم وضع أفضل الممارسات في الاعتبار حتى يستمتع المستخدمون باستخدام تطبيقك. تأكد مما يلي:

  • انتظر حتى يظهر لك أول إعلان على شاشة فتح التطبيق إلى أن يستخدم المستخدِمون التطبيق عدة مرات.
  • عرض الإعلانات على شاشة فتح التطبيق خلال الأوقات التي ينتظر فيها المستخدمون الانتظار لولا ذلك لتحميل تطبيقك
  • ظهور شاشة تحميل أسفل الإعلان على شاشة فتح التطبيق وشاشة التحميل يُكتمل التحميل قبل أن يتم تجاهل الإعلان، فيمكنك إزالة تحميل الشاشة بطريقة adDidDismissFullScreenContent.

مثال كامل على GitHub

Swift الهدف-ج

الخطوات التالية

مزيد من المعلومات حول خصوصية المستخدم