Offerwall Custom Choice API

はじめに

Offerwall Custom Choice API を使用すると、Google アド マネージャーOfferwall に独自のカスタム収益化ソリューションを統合できます。

独自の収益化ソリューションをオファーウォールに統合するには、カスタム選択オプションの設定の手順に沿って操作します。まとめると、次のとおりです。

  1. アド マネージャーの [プライバシーとメッセージ] タブで、オファーウォールの [カスタム チョイス] オプションを有効にします。

  2. Offerwall を公開したサイトの <head> タグと </head> タグの間にカスタム JavaScript を追加します。

  3. 以降のセクションで定義されている CustomOfferwallChoice オブジェクトをインスタンス化し、ウィンドウのオファーウォールに登録します。

サンプルコード

すぐに始めるには、Offerwall Custom Choice API の実装のサンプルをご覧ください。

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>

カスタムの収益化ソリューションを初期化します。この関数は他のどの関数よりも前に呼び出され、特定のページ読み込みで最大 1 回呼び出されることが想定されます。

  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 が解決されるまで Offerwall は非表示になります。それまでの間、CustomOfferwallChoice がページ コンテンツをゲートで制御する必要があります。この Promise が解決されたら、CustomOfferwallChoice がウェブページに表示されなくなったことを確認する必要があります。

show() 関数の Promise が解決されたら、次の処理を行う必要があります。

  • レンダリングされた収益化ソリューションを非表示にします。

  • ユーザーがページ コンテンツにアクセスできたかどうかを示すブール値を返します。

    • true: ユーザーがページ コンテンツにアクセスしました。この場合、Promise の解決時に Offerwall が再度レンダリングされることはありません。
    • 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 オファーウォールでカスタム チョイスのオプションを無効にします。カスタム チョイスが無効になっている場合、Offerwall は他の有効なチョイスでのみレンダリングできます。他のチョイスが有効でない場合、Offerwall はページにレンダリングされません。
ACCESS_GRANTED ページ読み込み時にユーザーにページへのアクセス権を付与します。このレスポンスが返された場合、Offerwall はページに表示されません。
ACCESS_NOT_GRANTED ページ読み込み時にユーザーにページアクセスを許可しないでください。このレスポンスが返された場合、Offerwall はページにレンダリングできます。