Offerwall Custom Choice API

简介

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

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

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

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

  3. 按照以下部分中所定义的方式实例化 CustomOfferwallChoice 对象,并在窗口上将其注册到您的积分墙。

API 应用

CustomOfferwallChoice 是一种 JavaScript 对象,您可以将其插入积分墙以集成自定义变现实现。

// 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>

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

解析 show() 函数的 promise 后,您必须:

  • 隐藏呈现的变现解决方案。

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

    • true:用户获得了对网页内容的访问权限。在这种情况下,您的积分墙在 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 您要投放的积分墙的语言代码(按照 BCP 47 的定义)。

枚举定义

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

googlefc.offerwall.customchoice.InitializeResponseEnum

initialize 函数的响应枚举类型。

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