横幅和 MREC

由于最新版本的 AppLovin MAX Unity 插件已默认启用自适应横幅,因此部分平台的横幅高度可能会超过 50 点。 横幅高度绝不会超过设备当前方向高度的 15%,且绝不会低于 50 点。 请查看下方 自适应横幅 部分,了解详情。

横幅和 MREC 广告均为矩形的广告格式,会占据应用版面中的一部分,通常位于屏幕顶部或底部,有时也内嵌在可滚动的内容中。用户与应用互动时,横幅和 MREC 广告始终可见,既不会干扰或打断游戏和使用体验,也可以在指定时间周期后自动刷新。

以下各节将向您介绍如何加载、显示和隐藏横幅或 MREC 广告。

加载横幅或 MREC

要加载横幅或 MREC,请使用如下代码,在其中添加您的 ad unit ID 和所需的广告展示位置:

#if UNITY_IOS
string bannerAdUnitId = "«iOS-ad-unit-ID»"; // Retrieve the ID from your account
#else // UNITY_ANDROID
string bannerAdUnitId = "«Android-ad-unit-ID»"; // Retrieve the ID from your account
#endif

public void InitializeBannerAds()
{
  // Banners are automatically sized to 320×50 on phones and 728×90 on tablets
  // You may call the utility method MaxSdkUtils.isTablet() to help with view sizing adjustments
  var adViewConfiguration = new MaxSdk.AdViewConfiguration(MaxSdk.AdViewPosition.BottomCenter);
  MaxSdk.CreateBanner(bannerAdUnitId, adViewConfiguration);

  // Set background color for banners to be fully functional
  MaxSdk.SetBannerBackgroundColor(bannerAdUnitId, «banner-background-color»);

  MaxSdkCallbacks.Banner.OnAdLoadedEvent      += OnBannerAdLoadedEvent;
  MaxSdkCallbacks.Banner.OnAdLoadFailedEvent  += OnBannerAdLoadFailedEvent;
  MaxSdkCallbacks.Banner.OnAdClickedEvent     += OnBannerAdClickedEvent;
  MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnBannerAdRevenuePaidEvent;
  MaxSdkCallbacks.Banner.OnAdExpandedEvent    += OnBannerAdExpandedEvent;
  MaxSdkCallbacks.Banner.OnAdCollapsedEvent   += OnBannerAdCollapsedEvent;
}

private void OnBannerAdLoadedEvent(string adUnitId, MaxSdk.AdInfo adInfo) {}

private void OnBannerAdLoadFailedEvent(string adUnitId, MaxSdk.ErrorInfo errorInfo) {}

private void OnBannerAdClickedEvent(string adUnitId, MaxSdk.AdInfo adInfo) {}

private void OnBannerAdRevenuePaidEvent(string adUnitId, MaxSdk.AdInfo adInfo) {}

private void OnBannerAdExpandedEvent(string adUnitId, MaxSdk.AdInfo adInfo)  {}

private void OnBannerAdCollapsedEvent(string adUnitId, MaxSdk.AdInfo adInfo) {}

将横幅背景颜色设置为以 # 为前缀的十六进制 RGB 字符串,例如 '#000000' (黑色) 或 '#fff200' (黄色)。

以下为完整的位置选项列表:

  • TopLeft
  • TopCenter
  • TopRight
  • Centered
  • CenterLeft
  • CenterRight
  • BottomLeft
  • BottomCenter
  • BottomRight

您也可以调用 MaxSdk.CreateBanner(«ad-unit-ID», new MaxSdk.AdViewConfiguration(«x», «y»));MaxSdk.CreateMRec(«ad-unit-ID», new MaxSdk.AdViewConfiguration(«x», «y»));,将广告放置在屏幕具体的 (xy) 坐标上。此操作可设置广告左上角的位置。 该坐标系代表屏幕的安全区域边界。 在设置这些坐标时,请务必考虑到广告的宽度和高度。 位置 (0, 0) 为 TopLeft;安全区域的右下角为 (safeAreaWidth, safeAreaHeight)。 请注意,Unity 的屏幕尺寸或安全区域大小可能与 Android 或 iOS 不同。 要在 Unity 的屏幕尺寸和 Android 或 iOS 使用的尺寸之间进行转换,请使用如下代码:

var density = MaxSdkUtils.GetScreenDensity();
var dp = «pixels» / density;

显示横幅或 MREC

要显示横幅或 MREC,请进行以下调用:

MaxSdk.ShowBanner(«ad-unit-ID»);

隐藏横幅或 MREC

要隐藏横幅或 MREC,请进行如下调用:

MaxSdk.HideBanner(«ad-unit-ID»);

销毁横幅或 MREC

某些情况下,您可能不再需要某个广告实例 (例如用户购买了广告移除服务)。 此时,请调用 DestroyBanner()DestroyMRec() 方法来释放资源。 如果您使用带有相同 Ad Unit ID 的多个广告实例,那么请勿调用 DestroyBanner()DestroyMRec()

MaxSdk.DestroyBanner(«ad-unit-ID»);

获取横幅位置

要获取横幅的位置和尺寸,请调用 GetBannerLayout()。 此操作使用的 Unity 坐标系与 加载横幅 or MREC 中所述的相同。

Rect bannerLayout = MaxSdk.GetBannerLayout(«ad-unit-ID»);

设置横幅宽度

To manually set a banner’s width, call SetBannerWidth().

MaxSdk.SetBannerWidth(«ad-unit-ID», «width»);

Set the banner width to a size larger than the minimum value (320 on phones, 728 on tablets). The advertiser may consider banners under this width to be not-viewable, which affects your revenue. If you set the banner width below the minimum, you will see an error message in your logs. For example:

[AppLovinSdk] [MAUnityAdManager] The provided width: 300.000000 is smaller than the minimum required width: 320.000000 for ad format: [MAAdFormat: BANNER]. Please set the width higher than the minimum required.

自适应横幅

MAX Unity 插件会在 Liftoff Monetize、Google 竞价、Google AdMob 和 Google Ad Manager 上自动启用自适应横幅广告。 这可以帮助您增加收入。 AppLovin 建议您进行测试,确保自适应横幅能为用户带来最佳体验。 如需禁用自适应横幅,请按照以下说明操作。

Google recommends that developers include a 50 px padding between the banner placement and the app content. This makes accidental clicks less likely. Refer to Google’s “About Confirmed Click” policy for more information and best practices.

自适应横幅是响应性横幅,其高度取决于设备类型和横幅宽度。 来自支持自适应横幅的广告平台的横幅默认为自适应横幅。 如果您想禁用自适应横幅,请在创建横幅时将横幅额外参数 adaptive_banner 设置为 false,如下所示:

#if UNITY_IOS
string bannerAdUnitId = "«iOS-ad-unit-ID»"; // Retrieve the ID from your account
#else // UNITY_ANDROID
string bannerAdUnitId = "«android-ad-unit-ID»"; // Retrieve the ID from your account
#endif

public void InitializeBannerAds()
{
  var adViewConfiguration = new MaxSdk.AdViewConfiguration(CurrentBannerPosition)
  {
    IsAdaptive = false
  };
  MaxSdk.CreateBanner(bannerAdUnitId, adViewConfiguration);

  // Set background or background color for banners to be fully functional
  MaxSdk.SetBannerBackgroundColor(bannerAdUnitId, «background-color»);
}

调用 MaxSdkUtils.GetAdaptiveBannerHeight() 来获取横幅高度,然后据此调整内容。

横幅位置为 TopCenterBottomCenter 时,横幅会覆盖整个屏幕宽度。 使用其他位置时,横幅的宽度为 320 (手机) 或 728 (平板电脑)。 MaxSdkUtils.GetAdaptiveBannerHeight(width) 函数接收一个 width 参数,并根据指定的横幅宽度返回相应的自适应高度。

停止和启动自动刷新

某些情况下,您可能需要停止广告的自动刷新,例如想要手动刷新横幅广告时。 要停止横幅广告或 MREC 广告的自动刷新,请使用以下代码:

MaxSdk.StopBannerAutoRefresh(«ad-unit-ID»);

使用以下代码为横幅或 MREC 广告启动自动刷新:

MaxSdk.StartBannerAutoRefresh(«ad-unit-ID»);

使用以下代码手动刷新内容。 在调用 LoadBanner()LoadMRec() 之前,您必须停止自动刷新。

MaxSdk.LoadBanner(«ad-unit-ID»);

这篇文章有帮助吗?
这篇文章有帮助吗?
search