设置

通过自定义事件,您可以为不受支持的广告联盟添加广告瀑布流中介。为此,您可以为要集成的广告联盟实现自定义事件适配器。

前提条件

您必须先将以下广告格式之一集成到您的应用中,然后才能创建自定义事件:

在界面中创建自定义事件

必须先在 Ad Manager界面中创建自定义事件。请参阅 创建和管理收益组

您需要提供以下信息:

课程名称

实现自定义事件适配器的类的完全限定名称,例如 com.google.ads.mediation.sample.customevent.SampleCustomEvent。我们建议的最佳做法是,为所有自定义事件广告格式使用同一个适配器类。

标签

定义广告来源的唯一名称。

参数

传递给自定义事件适配器的可选字符串参数。

初始化适配器

当 Google 移动广告 SDK 初始化时,系统会针对在 Ad Manager 界面中为应用配置的所有受支持的第三方适配器和自定义事件调用 initialize() 。使用此方法可对自定义事件所需的第三方 SDK 执行任何必要的设置或初始化。

Java

package com.google.ads.mediation.sample.customevent;

import com.google.android.gms.ads.AdFormat;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.InitializationCompleteCallback;
import com.google.android.gms.ads.mediation.MediationConfiguration;
...

public class SampleAdNetworkCustomEvent extends Adapter {

    private static final String SAMPLE_AD_UNIT_KEY = "parameter";

    private InitializationCompleteCallback initializationCallback;

    @Override
    public void initialize(Context context,
            InitializationCompleteCallback initializationCompleteCallback,
            List<MediationConfiguration> mediationConfigurations) {
        // This is where you will initialize the SDK that this custom
        // event is built for. Upon finishing the SDK initialization,
        // call the completion handler with success.
        initializationCompleteCallback.onInitializationSucceeded();
    }
}

报告版本号

所有自定义事件都必须向 Google 移动广告 SDK 报告自定义事件适配器本身的版本,以及与自定义事件对接的第三方 SDK 的版本。报告版本时使用的是 VersionInfo 对象:

Java

package com.google.ads.mediation.sample.customevent;

public class SampleCustomEvent extends Adapter {

  @Override
  public VersionInfo getVersionInfo() {
    String versionString = new VersionInfo(1, 2, 3);
    String[] splits = versionString.split("\\.");

    if (splits.length >= 4) {
      int major = Integer.parseInt(splits[0]);
      int minor = Integer.parseInt(splits[1]);
      int micro = Integer.parseInt(splits[2]) * 100 + Integer.parseInt(splits[3]);
      return new VersionInfo(major, minor, micro);
    }

    return new VersionInfo(0, 0, 0);
  }

  @Override
  public VersionInfo getSDKVersionInfo() {
    String versionString = SampleAdRequest.getSDKVersion();
    String[] splits = versionString.split("\\.");

    if (splits.length >= 3) {
      int major = Integer.parseInt(splits[0]);
      int minor = Integer.parseInt(splits[1]);
      int micro = Integer.parseInt(splits[2]);
      return new VersionInfo(major, minor, micro);
    }

    return new VersionInfo(0, 0, 0);
  }
}

请求广告

要请求广告,请参阅广告格式的具体说明: