Ads

From GiderosMobile

Supported platforms: Platform android.pngPlatform ios.pngPlatform html5.pngPlatform winrt.png
Available since: Gideros 2011.6
Inherits from: EventDispatcher

Description

The idea is to provide a common Ads Interface for most ad frameworks, allowing switching and fall back between ad frameworks at runtime.

Gideros Common Ads Interface provides:

  • using the same interface not only across platforms, but also across ad frameworks
  • ability to use multiple ad frameworks simultaneously
  • easily create fall backs to other frameworks if one framework failed
  • displaying and hiding banners
  • preloading ads without showing them
  • banners dimensions and position as any other Gideros element
  • tween banners using GTween
  • place personalized ads (Bitmap objects) under banners if there is no ad or Internet connection
  • test ads with one simple call (depends on ad framework)

To add the Ads plugin to your project:

require "ads"

Then in the Plugins Folder you can right click the Ads plugin -> Properties and configure it as desired.

You can also add the Require plugin to further configure your app (right click -> Properties).

Examples

Admob

Ads = Core.class(Sprite) -- you need to add "Ads" and "Gaming" to your project Plugins

function Ads:init()
	-- ads
	self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google test id
	self.ADMOB_UNIT_ID = "ca-app-pub-3940256099942544/6300978111" -- google test id

	-- admob (setup for simple banner adverts), note: only visible on phone/tablet
	if application:getDeviceInfo() == "Android" then
		require 'ads' --create real object for on device
		self.ADMOB = Ads.new('admob')
		self.ADMOB:setKey(self.ADMOB_APP_ID)
		self.ADMOB:addEventListener(Event.AD_RECEIVED, function() -- show ad
			self.ADMOB:showAd('banner')
			self.ADMOB:setAlignment('center', 'bottom')
		end)
		self.ADMOB:addEventListener(Event.AD_FAILED, function(e) end)
		self.ADMOB:addEventListener(Event.AD_ACTION_BEGIN, function() end)
		self.ADMOB:addEventListener(Event.AD_ACTION_END, function() end)
		self.ADMOB:addEventListener(Event.AD_DISMISSED, function() end)

		self.ADMOB:loadAd("banner", self.ADMOB_UNIT_ID) -- load ad
	else
		self.ADMOB = {} -- create fake object for testing in windows player
		self.ADMOB.loadAd = function() end
		self.ADMOB.showAd = function() end
	end
end

Creating fallbacks with Ads frameworks

--require plugin
require "ads"

--initialize amazon
amazon = Ads.new("amazon")
amazon:setKey("amazon-key")

--initialize admob
admob = Ads.new("admob")
admob:setKey("admob-key")

--if amazon fails
--show admob
amazon:addEventListener(Event.AD_FAILED, function(e)
	print("amazon AD_FAILED", e.error)
	admob:showAd("auto")
end)

--if admob fails
--show amazon
admob:addEventListener(Event.AD_FAILED, function(e)
	print("admob AD_FAILED", e.error)
	amazon:showAd("auto")
end)

--start displaying amazon ads
amazon:showAd("auto")

Methods

Ads.new initializes new ad framework
Ads:checkConsent triggers consent flow if needed
Ads:enableTesting enables ads testing
Ads:get gets ad property value
Ads:getHeight gets ad height
Ads:getPosition gets ad x and y position
Ads:getWidth gets ad width
Ads:getX gets ad x position
Ads:getY gets ad y position
Ads:hideAd hides ad
Ads:loadAd loads ad
Ads:set sets ad property value
Ads:setAlignment sets ad alignment
Ads:setKey sets framework key
Ads:setPosition sets ad position
Ads:setX sets ad x position
Ads:setY sets ad y position
Ads:showAd displays ad

Events

Event.AD_ACTION_BEGIN
Event.AD_ACTION_END
Event.AD_CONSENT
Event.AD_DISMISSED
Event.AD_DISPLAYED
Event.AD_ERROR
Event.AD_FAILED
Event.ADS_READY
Event.AD_RECEIVED
Event.AD_REWARDED

Constants