Skip to content

Video ads

We support two different types of video ads: midgame and rewarded.

Midgame advertisements can happen when a user died, a level has been completed, etc.

Rewarded advertisements can be requested by the user in exchange for a reward (An additional life, a retry when the user died, a bonus starting item, extra starting health, etc.). Rewarded ads should be shown when users explicitly consent to watch an advertisement.

To react to an ad starting or finishing, the SDK offers three callbacks: adStarted, adError, and adFinished. The adError callback is also triggered if the ad is not filled. For each callback, create a Godot function with one argument. Within these functions, you can, for example, emit custom signals that other scripts can connect and react to. For example, you should pause the game and mute the audio during an ad.

# Example
signal ad_started
signal ad_finished
signal ad_error

func adStarted(args):

func adError(error):
    emit_signal("ad_error", error)

func adFinished(args):

The JavaScript callbacks have to be declared in global scope like this:

var adStartedCallback = JavaScript.create_callback(self, "adStarted")
var adErrorCallback = JavaScript.create_callback(self, "adError")
var adFinishedCallback = JavaScript.create_callback(self, "adFinished")

Define a JavaScript object in global scope to encapsulate all three callbacks.

var adCallbacks = JavaScript.create_object("Object")

In the _ready function, add the three callbacks like this:

adCallbacks["adFinished"] = adFinishedCallback
adCallbacks["adError"] = adErrorCallback
adCallbacks["adStarted"] = adStartedCallback

Now, to request an ad, call:

# midgame ad"midgame", adCallbacks)
# rewarded ad"rewarded", adCallbacks)

Adblock detection

To detect if the user has an adblocker, the ad module offers the method hasAdblock:

func detectAdblock():

Define a function to receive the result. From there, you can emit a signal for other scripts to connect to, for example.

signal adblock_result

func adblockResult(args):
    var error = args[0]
    var result = args[1]
    emit_signal("adblock_result", error, result)

Create a callback to it in global scope:

var adblockCallback = JavaScript.create_callback(self, "adblockResult")

Through the callback, the SDK will return an array, the first element tells you whether an error occurred during adblock detection. If none occured, the second element tells you whether the user has an adblock active.