unityads.init()

Type Function
Return value none
Revision Release 2024.3703
Keywords ads, advertising, Unity Ads, init
See also unityads.show()
unityads.*

Overview

unityads.init() initializes the Unity Ads plugin. This call is required and must be executed before making other Unity Ads calls such as unityads.show() or unityads.load().

Syntax

unityads.init( listener, params )
listener (required)

Listener. Listener function that will receive adsRequest events.

params (required)

Table. Table containing Unity Ads initialization values — see the next section for details.

Parameter Reference

The params table includes parameters for Unity Ads initialization.

gameId (required)

String. The game ID for your app, gathered from the Unity Ads dashboard.

testMode (optional)

Boolean. Set this value to true to enable test ads. Default is false.

Example

local unityads = require( "plugin.unityads.v4" )

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

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

-- Initialize the Unity Ads plugin
unityads.init( adListener, { gameId="YOUR_UNITYADS_GAME_ID" } )