// Define your custom choice.classCustomOfferwallChoice{// Initialize your custom choice, which may include loading or preparing any// resources required to function.asyncinitialize(params:InitializeParams):Promise<InitializeResponseEnum>{...}// Show your custom choice on the web page, which may be a subscription// service, micropayments service, rewarded ad, etc.asyncshow():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=newCustomOfferwallChoice();
asyncinitialize(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.constisCustomChoiceEnabled:boolean=awaitthis.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.constisAccessGranted:boolean=awaitthis.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);}
asyncshow():Promise<boolean>{// Show your custom choice dialog and hide it once the user completes an action.constdidUserGainAccessToPage:boolean=awaitthis.showCustomChoiceDialogUntilUserAction();resolve(didUserGainAccessToPage);}
// 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=newCustomOfferwallChoice();
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["# Offerwall Custom Choice API\n\n| **Note:** This API uses [TypeScript](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html) notation to describe types, however, implementations can be written in any language that compiles to JavaScript.\n\nIntroduction\n------------\n\nThe Offerwall Custom Choice API lets you integrate your own custom monetization\nsolution with\n[Offerwall](https://support.google.com/admanager/answer/13860694) in\n[Google Ad Manager](https://support.google.com/admanager/answer/6022000).\n\nTo integrate your own monetization solution with Offerwall, follow\nthese [Custom Choice setup](https://support.google.com/admanager/answer/13566866)\nsteps. In summary:\n\n1. Enable the \"Custom Choice\" option for your Offerwall from within the [Privacy \\& messaging](https://support.google.com/admanager/answer/10075997) tab in Ad Manager.\n\n2. Add custom JavaScript between the `\u003chead\u003e` and `\u003c/head\u003e` tags of the site where you have published your Offerwall.\n\n3. Instantiate a `CustomOfferwallChoice` object as defined in the sections that follow, and [register](#custom-choice-registration) it with your Offerwall on the window.\n\nAPI Usage\n---------\n\nA `CustomOfferwallChoice` is a JavaScript object that you plug in to your\nOfferwall to integrate your custom monetization implementation. \n\n // Define your custom choice.\n class CustomOfferwallChoice {\n // Initialize your custom choice, which may include loading or preparing any\n // resources required to function.\n async initialize(params: InitializeParams): Promise\u003cInitializeResponseEnum\u003e {...}\n\n // Show your custom choice on the web page, which may be a subscription\n // service, micropayments service, rewarded ad, etc.\n async show(): Promise\u003cboolean\u003e {...}\n }\n\n // Register your custom choice with your Offerwall.\n window.googlefc = window.googlefc || {};\n window.googlefc.offerwall = window.googlefc.offerwall || {};\n window.googlefc.offerwall.customchoice = window.googlefc.offerwall.customchoice || {};\n window.googlefc.offerwall.customchoice.registry = new CustomOfferwallChoice();\n\n### Method Definitions\n\nThis section describes each method that a `CustomOfferwallChoice` is required to\nimplement.\n\n#### initialize\n\n`initialize(params: `[InitializeParams](#initialize-params)`): Promise\u003c`[InitializeResponseEnum](#initialize-response-enum)`\u003e`\n\nInitialize your custom monetization solution. This function is invoked before\nany other function, and can be expected to be invoked at most once on a given\npage load.\n| **Caution:** This function must resolve in under 1 second, or your Offerwall may not render on the web page.\n\n**Example** \n\n async initialize(params: InitializeParams): Promise\u003cInitializeResponseEnum\u003e {\n // If your custom choice is inoperable on this page, return CUSTOM_CHOICE_DISABLED,\n // causing your Offerwall to exclude the custom choice option when rendering.\n const isCustomChoiceEnabled: boolean = await this.initializeCustomOfferwallChoice(params);\n if (!isCustomChoiceEnabled) {\n resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.CUSTOM_CHOICE_DISABLED);\n }\n\n // If the user should automatically be granted page access on page load, return\n // ACCESS_GRANTED, causing your Offerwall to be ineligible to render on this page.\n const isAccessGranted: boolean = await this.shouldUserBeGrantedPageAccess();\n if (isAccessGranted) {\n resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.ACCESS_GRANTED);\n }\n\n // If the user shouldn't automatically be granted page access on page load, return\n // ACCESS_NOT_GRANTED, causing your Offerwall to be eligible to render on this page.\n resolve(googlefc.offerwall.customchoice.InitializeResponseEnum.ACCESS_NOT_GRANTED);\n }\n\n*** ** * ** ***\n\n#### show\n\n`show(): Promise\u003cboolean\u003e`\n\nRender your custom monetization solution and handle the user's monetization\nactions. This method is invoked by your Offerwall when the user clicks on the\ncustom choice option. Monetization can take any form, including a subscription\nservice, micropayments service, rewarded ad, and more. When invoked, your\nOfferwall is hidden until this promise is resolved and it is the responsibility\nof your `CustomOfferwallChoice` to gate page content in the meantime. Once this\npromise is resolved, your `CustomOfferwallChoice` must be sure to no longer be\nvisible on the web page.\n\nUpon resolution of the `show()` function's promise, you must:\n\n- Hide your rendered monetization solution.\n\n- Return a boolean value indicating whether the user gained access to page content:\n\n - `true`: User gained access to page content. In this case, your Offerwall won't be rendered again upon promise resolution.\n - `false`: User did not gain access to page content. In this case, your Offerwall will be rendered again upon promise resolution.\n\n**Example** \n\n async show(): Promise\u003cboolean\u003e {\n // Show your custom choice dialog and hide it once the user completes an action.\n const didUserGainAccessToPage: boolean = await this.showCustomChoiceDialogUntilUserAction();\n\n resolve(didUserGainAccessToPage);\n }\n\n*** ** * ** ***\n\n### Custom Choice Registration\n\nRegistration includes passing your instantiated `CustomOfferwallChoice` object\nto the following window registry:\n`window.googlefc.offerwall.customchoice.registry`\n| **Important:** The parent namespaces of the registry should only be newly instantiated as objects if they don't already exist, to avoid overwriting other components of the API.\n\n**Example** \n\n // Register your custom choice with your Offerwall.\n window.googlefc = window.googlefc || {};\n window.googlefc.offerwall = window.googlefc.offerwall || {};\n window.googlefc.offerwall.customchoice = window.googlefc.offerwall.customchoice || {};\n window.googlefc.offerwall.customchoice.registry = new CustomOfferwallChoice();\n\nAPI Type Definitions\n--------------------\n\nThis section describes each data type in the API.\n\n### Object Definitions\n\nThis section describes each object definition in the API.\n\n#### InitializeParams\n\nThe parameter object type for the [initialize](#initialize) function.\n\n| Property | Type | Description |\n|-------------------------|----------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `offerwallLanguageCode` | `string | undefined` | The language code of your Offerwall that is being served, as defined by [BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag). |\n\n### Enum Definitions\n\nThis section describes each enum definition in the API.\n\n#### googlefc.offerwall.customchoice.InitializeResponseEnum\n\nThe response enum type for the [initialize](#initialize) function.\n\n| Enumeration member | Description |\n|--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `CUSTOM_CHOICE_DISABLED` | Disable the custom choice option in your Offerwall. If custom choice is disabled, your Offerwall can only render with other eligible choices; if no other choices are eligible, your Offerwall won't ever render on the page. |\n| `ACCESS_GRANTED` | Grant the user page access on page load. Your Offerwall won't ever render on the page if this response is returned. |\n| `ACCESS_NOT_GRANTED` | Don't grant the user page access on page load. Your Offerwall is eligible to render on the page if this response is returned. |"]]