fbAudienceNetwork.show()

Type Function
Return value none
Revision Release 2022.3683
Keywords ads, advertising, Facebook Audience Network, fbAudienceNetwork, show
See also fbAudienceNetwork.hide()
fbAudienceNetwork.init()
fbAudienceNetwork.load()
fbAudienceNetwork.isLoaded()
fbAudienceNetwork.*

Overview

Shows a Facebook ad which was previously loaded via fbAudienceNetwork.load().

Syntax

fbAudienceNetwork.show( adUnitType, params )
adUnitType (required)

String. The type of ad according to your Facebook placement ID. Supported values are "banner", "rewardedVideo" or "interstitial".

params (required)

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.

placementId (required)

String. The placement ID for this ad, retrieved from the Facebook Developer Portal.

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", "center" and "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".

Example

local fbAudienceNetwork = require( "plugin.fbAudienceNetwork" )

-- Pre-declare a placement ID
local myPlacementID = "YOUR_PLACEMENT_ID"

local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        -- Load a banner ad
        fbAudienceNetwork.load( "banner", { placementId=myPlacementID, bannerSize="BANNER_320_50" } )

    elseif ( event.phase == "loaded" ) then  -- The ad was successfully loaded
        print( event.type )
        print( event.placementId )
    end
end

-- Initialize the Facebook Audience Network
fbAudienceNetwork.init( adListener )

-- Sometime later, check if the ad is loaded and display it
if ( fbAudienceNetwork.isLoaded( myPlacementID ) ) then
    fbAudienceNetwork.show( "banner", { placementId=myPlacementID, y="center" } )
end