This is an integration of the KaiAds SDK with the Defold game engine. The integration is created as a Defold native extension.
To use KaiAds in your Defold project, add the following URL to your game.project dependencies:
https://github.com/defold/extension-kaiads/archive/main.zip
We recommend using a link to a zip file of a specific release.
The following functions are available from Lua:
kaiads.init(publisher)
- Initialize KaiAds with your publisher idkaiads.set_listener(fn)
- Callback function which will receive ad eventskaiads.preload(configuration)
- Preload an ad using the provided JSON encoded Lua table with ad configuration values (see below)kaiads.show()
- Show the ad if it was successfully preloaded (event == kaiads.PRELOAD_OK)
The following ad events are available:
PRELOAD_ERROR
- Error when preloading adPRELOAD_OK
- Ad successfully preloadedSHOW_ERROR
- Error when showing adAD_DISPLAY
- Ad successfully displayed on deviceAD_CLICK
- User clicked the adAD_CLOSE
- User closed the ad
Possible values in the configuration table:
app
= Optional, application name, used for reporting, for your own convenienceslot
= Optional, ad slot name, used for reporting, for your own conveniencecontainer
= Id of HTML div to load banner ad intest
= Optional. Enable test mode. Please set this to 1 when testing the ad, 0 or omitted when in production.
Refer to KaiAds SDK documentation for more information on how to configure ads.
local json = require "kaiads.json"
local function on_kaiads_event(self, event, code)
if event == kaiads.PRELOAD_OK then
print("KaiAds has successfully preloaded an ad")
kaiads.show()
elseif event == kaiads.AD_DISPLAY then
print("KaiAds is showing an ad")
elseif event == kaiads.AD_CLOSE then
print("The user closed the ad!")
elseif event == kaiads.AD_CLICK then
print("The user clicked on the ad!")
else
print("Something went wrong", code)
end
end
function init(self)
if kaiads then
kaiads.set_listener(on_kaiads_event)
kaiads.init("2b30c65e-efde-4930-990e-ded207899766")
local fullscreen_config = {
app = "mygame",
slot = "gameover",
}
kaiads.preload(json.encode(fullscreen_config))
end
end