Offerwall Custom Choice API

简介

借助积分墙自定义选项 API,您可以将自己的自定义变现解决方案与 Google Ad Manager 中的Offerwall集成。

如需将您自己的变现解决方案与积分墙集成,请按照以下自定义选项设置步骤操作。总结:

  1. 在 Ad Manager 的隐私权和消息标签页中,为积分墙启用“自定义选项”。

  2. 在发布了积分墙的网站的 <head></head> 标记之间添加自定义 JavaScript。

  3. 实例化一个 CustomOfferwallChoice 对象(如后续部分中所述),并将其注册到窗口中的积分墙。

示例代码

如需快速入门,请参阅积分墙自定义选项 API 实现的实用示例

API 应用

CustomOfferwallChoice 是一个 JavaScript 对象,您可以将其插入到 Offerwall 中,以集成自定义创收实现。

// Define your custom choice.
class CustomOfferwallChoice {
  // Initialize your custom choice, which may include loading or preparing any
  // resources required to function.
  async initialize(params: InitializeParams): Promise<InitializeResponseEnum> {...}

  // Show your custom choice on the web page, which may be a subscription
  // service, micropayments service, rewarded ad, etc.
  async show(): Promise<boolean> {...}
}

// Register your custom choice with your Offerwall.
window.googlefc = window.googlefc || {};
window.googlefc.offerwall = window.googlefc.offerwall || {};
window.googlefc.offerwall.customchoice = window.googlefc.offerwall.customchoice || {};
window.googlefc.offerwall.customchoice.registry = new CustomOfferwallChoice();

方法定义

本部分介绍了 CustomOfferwallChoice 必须实现的方法。

initialize

initialize(params: InitializeParams): Promise<InitializeResponseEnum>

初始化自定义创收解决方案。此函数会在任何其他函数之前调用,并且在给定的页面加载时最多调用一次。

示例

  async initialize(params: InitializeParams): Promise<InitializeResponseEnum> {
    // If your custom choice is inoperable on this page, return CUSTOM_CHOICE_DISABLED,
    // causing your Offerwall to exclude the custom choice option when rendering.
    const isCustomChoiceEnabled: boolean = await this.initializeCustomOfferwallChoice(params);
    if (!isCustomChoiceEnabled) {
      resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.CUSTOM_CHOICE_DISABLED);
    }

    // If the user should automatically be granted page access on page load, return
    // ACCESS_GRANTED, causing your Offerwall to be ineligible to render on this page.
    const isAccessGranted: boolean = await this.shouldUserBeGrantedPageAccess();
    if (isAccessGranted) {
      resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.ACCESS_GRANTED);
    }

    // If the user shouldn't automatically be granted page access on page load, return
    // ACCESS_NOT_GRANTED, causing your Offerwall to be eligible to render on this page.
    resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.ACCESS_NOT_GRANTED);
  }

显示

show(): Promise<boolean>

呈现自定义变现解决方案并处理用户的变现操作。当用户点击自定义选项时,积分墙会调用此方法。变现可以采用任何形式,包括订阅服务、小额付款服务、激励广告等。调用后,Offerwall 会隐藏,直到此 promise 得到解决为止,在此期间,您需要负责使用 CustomOfferwallChoice 来控制网页内容。解决此承诺后,您的 CustomOfferwallChoice 必须确保不再显示在网页上。

show() 函数的 promise 得到解决后,您必须执行以下操作:

  • 隐藏呈现的创收解决方案。

  • 返回一个布尔值,指示用户是否获得了对网页内容的访问权限:

    • true:用户获得了对网页内容的访问权限。在这种情况下,Offerwall 在 Promise 解析后不会再次呈现。
    • false:用户未获得网页内容访问权限。在这种情况下,系统会在 promise 解析后重新呈现积分墙。

示例

  async show(): Promise<boolean> {
    // Show your custom choice dialog and hide it once the user completes an action.
    const didUserGainAccessToPage: boolean = await this.showCustomChoiceDialogUntilUserAction();

    resolve(didUserGainAccessToPage);
  }

自定义选项注册

注册包括将实例化的 CustomOfferwallChoice 对象传递给以下窗口注册表: window.googlefc.offerwall.customchoice.registry

示例

    // Register your custom choice with your Offerwall.
    window.googlefc = window.googlefc || {};
    window.googlefc.offerwall = window.googlefc.offerwall || {};
    window.googlefc.offerwall.customchoice = window.googlefc.offerwall.customchoice || {};
    window.googlefc.offerwall.customchoice.registry = new CustomOfferwallChoice();

API 类型定义

本部分介绍了 API 中的每种数据类型。

对象定义

本部分介绍了 API 中的每个对象定义。

InitializeParams

initialize 函数的形参对象类型。

属性 类型 说明
offerwallLanguageCode string | undefined 正在投放的 Offerwall 的语言代码,如 BCP 47 所定义。

枚举定义

本部分介绍了 API 中的每个枚举定义。

googlefc.offerwall.customchoice.InitializeResponseEnum

初始化函数的响应枚举类型。

枚举成员 说明
CUSTOM_CHOICE_DISABLED 停用积分墙中的自定义选项。如果自定义选项处于停用状态,您的积分墙只能通过其他符合条件的选项进行呈现;如果没有其他符合条件的选项,您的积分墙将永远不会在网页上呈现。
ACCESS_GRANTED 在页面加载时授予用户页面访问权限。如果返回此响应,积分墙将永远不会在网页上呈现。
ACCESS_NOT_GRANTED 请勿在页面加载时授予用户页面访问权限。如果返回此响应,则表示您的积分墙符合在网页上呈现的条件。