This is a Defold Game Engine native extension which provides Vungle Video Ads support.
Platforms supported are Android & Amazon Fire (aka. Android without Google Play services). Most ad networks with rewarded video do not support these Amazon devices, but Vungle does!
Disclaimer: This extension is independent and unofficial, and not associated with Vungle in any way.
Vundle SDK Version 6.11.0
https://github.com/Vungle/Android-SDK/blob/master/CHANGELOG.md
You can use the DefVungle extension in your own project by adding this project as a Defold library dependency. Open your game.project
file and add the latest release ZIP file URL to your dependencies:
https://github.com/SkaterDad/defold-vungle/archive/1.1.0.zip
If you prefer to walk on the wild side, you could point directly to the latest code, but I would not recommend it!
There is an example project in this repo which walks through the features. Here is a general overview.
Make sure you sign up on Vungle and create an application.
-- Define a callback function which handles Vungle-related events
local function defunityads_callback(self, msg_type, message)
-- if msg_type == ____ then
-- etc...
end
local function init_vungle()
if vungle then
vungle.init("my_vungle_app_id", defvungle_callback)
end
end
local function load_vungle_ads()
if vungle then
vungle.load("VIDEO-12345")
vungle.load("REWARDED-12345")
end
end
-- When ad is finished, the callback will receive a TYPE_DID_FINISH event.
if vungle and vungle.isReady("VIDEO-12345") then
vungle.show("VIDEO-12345")
end
-- When rewarded ad is finished, the callback will receive both TYPE_DID_FINISH and TYPE_DID_REWARD events.
if vungle and vungle.isReady("REWARDED-12345") then
vungle.show("REWARDED-12345")
end
function final(self)
if vungle then
vungle.setCallback()
end
end
In game.project
, set Android Minimum Sdk Version = 21.
vungle.initialize(app_id, callback)
vungle.isInitialized()
vungle.setCallback(callback)
vungle.load(placement_id)
vungle.isReady(placement_id)
vungle.show(placement_id)
vungle.TYPE_IS_READY
vungle.TYPE_DID_START
vungle.TYPE_DID_ERROR
vungle.TYPE_DID_FINISH
vungle.TYPE_DID_REWARD
vungle.TYPE_INITIALIZED
vungle.TYPE_INIT_ERROR
local function vungle_ads_callback(self, msg_type, message)
if msg_type == vungle.TYPE_IS_READY then
print(message.placementId, " is ready")
btn_ready(self, message.placementId)
elseif msg_type == vungle.TYPE_DID_START then
print(message.placementId, " started")
elseif msg_type == vungle.TYPE_DID_ERROR then
print(message.placementId, " error")
print(message.message) -- error message
elseif msg_type == vungle.TYPE_DID_FINISH then
print(message.placementId, " Ad finished")
elseif msg_type == vungle.TYPE_DID_REWARD then
print(message.placementId, " Rewarded Ad Complete")
elseif msg_type == vungle.TYPE_INITIALIZED then
print("Vungle init successful!")
elseif msg_type == vungle.TYPE_INIT_ERROR then
print("Vungle init error")
print(message.message)
end
end
When you set up an Amazon app in Vungle, those placements will only work on Amazon Fire devices. If run on a regular Android device, even if downloaded from the Amazon Appstore, Vungle will return errors about OS mismatches and not serve you ads. You will need a second app set up in Vungle, and submit 2 APKs to Amazon with different device targeting.
Upon initialization, the Vungle SDK starts to preload an interstitial ad automatically. It does not do this for rewarded ads.
Vungle support says it's okay to call 'load' during or after an ad is shown, to prefetch for next time.
Thanks to AGulev for his excellent DefVideoAds extension, which was forked to create this.