adSense.show()

Type Function
Return value none
Revision Release 2024.3703
Keywords AdSense, Google Ads, Google AdSense, show
See also adSense.init()
adSense.*

Overview

Shows AdSense Ad, you must call adSense.init() before calling. Only banners are supported at the moment.

Syntax

adSense.show( adType, parameters )
adType (required)

String. Currently "banner" is supported.

parameters (required)

Table. Table containing additional parameters for the specified ad type — see the next section for details.

Parameter Reference

adSlot (required)

String. Ad Slots is created under Console>Ads Overview>By Ad Unit>“Display ads” for banners. In the html code this called under the key data-ad-slot.

position (optional)

String. supported values are "top"(default) or "bottom".

height (optional)

[Number][api.type. Number]. default value is 100, this value is for Pixel Units(px).

width (optional)

[Number][api.type. Number]. default value full device width(100%), but setting a value is in Pixel Units(px).

Example

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"} )