adSense.show()

类型 函数
返回值
修订 版本 2024.3703
关键词 AdSense, Google Ads, Google AdSense, show
另请参阅 adSense.init()
adSense.*

概述

显示 AdSense 广告,您必须先调用 adSense.init()。 目前仅支持横幅广告。

语法

adSense.show( adType, parameters )
adType (必填)

字符串 当前支持 "banner"

parameters (必填)

包含指定广告类型附加参数的表 — 有关详细信息,请参阅下一节。

参数参考

adSlot (必填)

字符串 广告位是在控制台>广告概览>按广告单元>“展示广告”下为横幅广告创建的。 在 html 代码中,这在键 data-ad-slot 下调用。

position (可选)

字符串 支持的值为 "top"(默认)或 "bottom"

height (可选)

[数字][api.type. Number]。 默认值为 100,此值为像素单位 (px)。

width (可选)

[数字][api.type. Number]。 默认值为设备全宽 (100%),但设置的值以像素单位 (px) 为单位。

示例

local adSense = require( "plugin.adSense" )

-- AdSense Ads listener function
local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        adSense.show("banner",{adSlot="xxxxxxxxx", height=150, position="bottom"})

    end
end

-- Initialize Ad Sense
adSense.init(adListener, {clientId="ca-pub-xxxxxxxxxxxxxxxx"} )