fbAudienceNetwork.init()

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

Overview

fbAudienceNetwork.init() initializes the Facebook Audience Network.

Once initialized, you can load an ad using fbAudienceNetwork.load() and subsequently show it via fbAudienceNetwork.show().

Important

Facebook has a method for calling test ads which is different from other Corona ad providers. To test ads during implementation of this plugin, you must follow their requirements as follows:

  • Each testing device must be initialized within the system via a device hash ID. To gather a hash ID, you must first build and install your app on the device with a basic implementation of the Facebook Audience Network plugin. Next, call fbAudienceNetwork.load(). At this point, with the device connected, the app will output a message similar to the following to the device console log:

Test mode device hash: [HASHID]

This device hash can be used as one of the device hash IDs outlined below. For more information on accessing the device console log, see the Device Debugging sections of the Debugging Guide.

  • If you uninstall/remove your app from the device and then build/install it again, Facebook will generate a new device hash ID which you must update in your code.

Syntax

fbAudienceNetwork.init( adListener [, params] )
adListener (required)

Listener. Listener function that will receive adsRequest events.

params (optional)

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

Parameter Reference

The params table includes the following additional parameters:

testDevices (optional)

Array. Optional except when testing on devices. An array of device hash IDs, for instance { "deviceID1", "deviceID2" }.

Notes
  • When you are ready to distribute the app or test with real ads, you should not pass the testDevices parameter to this function.

  • Testing with real ads is a two-step process. The first step is to add testers to your app settings in the Facebook Developer Portal so they can see real ads before the app is approved. The second step is for those testers to be logged in to the Facebook app on the same device where your app is installed. See here for more information.

Example

local fbAudienceNetwork = require( "plugin.fbAudienceNetwork" )

local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        print( event.isError )
    end
end

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