admob.show()

Type Function
Return value none
Revision Release 2024.3703
Keywords ads, advertising, AdMob, show
See also admob.hide()
admob.load()
admob.isLoaded()
admob.*

Overview

Shows an AdMob interstitial, banner, rewarded interstitial, or rewarded video ad that was previously loaded with admob.load().

Important

Before attempting to show an ad, you must first load one via admob.load() and confirm it's ready to be shown. See the example below for basic usage details.

Syntax

admob.show( adType [, params] )
adType (required)

String. One of the following values:

  • "interstitial"
  • "banner"
  • "rewardedVideo"
  • "rewardedInterstitial"
  • "appOpen"
params (optional)

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

Parameter Reference

The params table includes parameters for the specified ad type.

y (optional)

String or Number. Only applies to banner ads, specifying the banner's y position on the screen. If you supply a string, valid position values are "top" or "bottom". Alternatively, you can set a custom y position by specifying a number in content coodinates where 0 indicates the top edge of the screen or where a negative value specifies an offset from the bottom edge of the screen to the bottom edge of the banner. Default is "bottom".

bgColor (optional)

String. Only applies to banner ads, specifying the background color of the smart banner. The value must be a hexadecimal RGB or ARGB value specified as "#RRGGBB" or "#AARRGGBB". Default is nil which will render the background as transparent.

Example

local admob = require( "plugin.admob" )

-- AdMob listener function
local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        -- Load an AdMob interstitial ad
        admob.load( "interstitial", { adUnitId="YOUR_ADMOB_AD_UNIT_ID" } )
    end
end

-- Initialize the AdMob plugin
admob.init( adListener, { appId="YOUR_ADMOB_APP_ID" } )

-- Sometime later, show the interstitial ad
if ( admob.isLoaded( "interstitial" ) ) then
    admob.show( "interstitial" )
end