Difference between revisions of "Ads"

From GiderosMobile
(added another example admob)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<languages />
 
 
 
<!-- GIDEROSOBJ:Ads -->
 
<!-- GIDEROSOBJ:Ads -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform html5.png]][[File:Platform winrt.png]]<br/>
 +
'''Available since:''' Gideros 2011.6<br/>
 +
'''Inherits from:''' [[EventDispatcher]]<br/>
  
'''<translate>Supported platforms</translate>:'''
+
=== Description ===
<br/>
+
The idea is to provide a common Ads Interface for most ad frameworks, allowing switching and fall back between ad frameworks at runtime.
'''<translate>Available since</translate>:''' Gideros 2011.6
 
<br/>
 
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/EventDispatcher|EventDispatcher]]
 
<br/>
 
  
=== <translate>Description</translate> ===
+
Gideros Common Ads Interface provides:
<translate>
+
* using the same interface not only across platforms, but also across ad frameworks
The idea is to provide common Ads interface for most of available ad frameworks, so that user's would not have to create a plugin for each of them separately, but rather it would be possible to wrap ad framework in single Java or Objective-C class (depending on the platform) and add it to the project, without even recompiling existing Ads Interface plugin.
+
* ability to use multiple ad frameworks simultaneously
<br/>
+
* 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)
  
Additionally it would be able to support multiple ad frameworks simultaneously so users could switch and fall back between ad frameworks on runtime.
+
To add the '''Ads plugin''' to your project:
<br/>
+
<syntaxhighlight lang="lua">
 +
require "ads"
 +
</syntaxhighlight>
  
More information available in [http://docs.giderosmobile.com/interface/ads](Ads interface guide).
+
Then in the '''Plugins Folder''' you can right click the '''Ads plugin''' -> ''Properties'' and configure it as desired.
</translate>
 
  
=== <translate>Examples</translate> ===
+
You can also add the '''Require plugin''' to further configure your app (right click -> ''Properties'').
<br/>
 
  
'''Example 1: Admob'''
+
=== Examples ===
<br/>
+
'''Admob'''
 
+
<syntaxhighlight lang="lua">
<source lang="lua">
 
 
Ads = Core.class(Sprite) -- you need to add "Ads" and "Gaming" to your project Plugins
 
Ads = Core.class(Sprite) -- you need to add "Ads" and "Gaming" to your project Plugins
  
 
function Ads:init()
 
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
  
  -- ads
+
-- admob (setup for simple banner adverts), note: only visible on phone/tablet
  self.ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713" -- google test id
+
if application:getDeviceInfo() == "Android" then
  self.ADMOB_UNIT_ID = "ca-app-pub-3940256099942544/6300978111" -- google test id
+
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)
  
  -- admob (setup for simple banner adverts), note: only visible on phone/tablet
+
self.ADMOB:loadAd("banner", self.ADMOB_UNIT_ID) -- load ad
  if application:getDeviceInfo() == "android" then
+
else
      require 'ads' --create real object for on device
+
self.ADMOB = {} -- create fake object for testing in windows player
      self.ADMOB = Ads.new('admob')
+
self.ADMOB.loadAd = function() end
      self.ADMOB:setKey(self.ADMOB_APP_ID)
+
self.ADMOB.showAd = function() end
      self.ADMOB:addEventListener(Event.AD_RECEIVED, function() -- show ad
+
end
        self.ADMOB:showAd('banner')
 
--        self.ADMOB:setAlignment('center', 'bottom')
 
        self.ADMOB:setAlignment('center', 'top')
 
      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)
 
  else
 
      self.ADMOB = {} -- create fake object for testing in windows player
 
      self.ADMOB.loadAd = function() end
 
      self.ADMOB.showAd = function() end
 
  end
 
 
 
  -- LISTENERS
 
  self:addEventListener("enterBegin", self.onTransitionInBegin, self)
 
  self:addEventListener("enterEnd", self.onTransitionInEnd, self)
 
  self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
 
  self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
 
 
 
end
 
 
 
-- EVENT LISTENERS
 
function Ads:onTransitionInBegin()
 
 
end
 
end
 +
</syntaxhighlight>
  
function Ads:onTransitionInEnd()
+
'''Creating fallbacks with Ads frameworks'''
  self.ADMOB:loadAd("banner", self.ADMOB_UNIT_ID)
+
<syntaxhighlight lang="lua">
end
 
 
 
function Ads:onTransitionOutBegin()
 
end
 
 
 
function Ads:onTransitionOutEnd()
 
end
 
</source>
 
<br/>
 
<br/>
 
 
 
'''Example 2: creating fallbacks with Ads frameworks'''
 
<br/>
 
 
 
<source lang="lua">
 
 
--require plugin
 
--require plugin
 
require "ads"
 
require "ads"
Line 114: Line 90:
 
--start displaying amazon ads
 
--start displaying amazon ads
 
amazon:showAd("auto")
 
amazon:showAd("auto")
</source>
+
</syntaxhighlight>
<br/>
 
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Ads.new|Ads.new]] ''<translate>initializes new ad framework</translate>''<br/><!-- GIDEROSMTD:Ads.new(adframework) initializes new ad framework -->
+
[[Ads.new]] ''initializes new ad framework''<br/><!--GIDEROSMTD:Ads.new(adframework) initializes a new ad framework-->
[[Special:MyLanguage/Ads:enableTesting|Ads:enableTesting]] ''<translate>enable testing ads</translate>''<br/><!-- GIDEROSMTD:Ads:enableTesting() enable testing ads -->
+
[[Ads:checkConsent]] ''triggers consent flow if needed''<br/><!--GIDEROSMTD:Ads:checkConsent(parameters) triggers consent flow if needed-->
[[Special:MyLanguage/Ads:get|Ads:get]] ''<translate>gets property value of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:get(property) gets property value of the ad -->
+
[[Ads:enableTesting]] ''enables ads testing''<br/><!--GIDEROSMTD:Ads:enableTesting() enables ads testing-->
[[Special:MyLanguage/Ads:getHeight|Ads:getHeight]] ''<translate>gets the height of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:getHeight() gets the height of the ad -->
+
[[Ads:get]] ''gets ad property value''<br/><!--GIDEROSMTD:Ads:get(property) gets ad property value-->
[[Special:MyLanguage/Ads:getPosition|Ads:getPosition]] ''<translate>gets x and y position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:getPosition() gets x and y position of the ad -->
+
[[Ads:getHeight]] ''gets ad height''<br/><!--GIDEROSMTD:Ads:getHeight() gets ad height-->
[[Special:MyLanguage/Ads:getWidth|Ads:getWidth]] ''<translate>gets width of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:getWidth() gets width of the ad -->
+
[[Ads:getPosition]] ''gets ad x and y position''<br/><!--GIDEROSMTD:Ads:getPosition() gets ad x and y position-->
[[Special:MyLanguage/Ads:getX|Ads:getX]] ''<translate>gets x position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:getX() gets x position of the ad -->
+
[[Ads:getWidth]] ''gets ad width''<br/><!--GIDEROSMTD:Ads:getWidth() gets ad width-->
[[Special:MyLanguage/Ads:getY|Ads:getY]] ''<translate>gets y position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:getY() gets y position of the ad -->
+
[[Ads:getX]] ''gets ad x position''<br/><!--GIDEROSMTD:Ads:getX() gets ad x position-->
[[Special:MyLanguage/Ads:hideAd|Ads:hideAd]] ''<translate>hides ads</translate>''<br/><!-- GIDEROSMTD:Ads:hideAd() hides ads -->
+
[[Ads:getY]] ''gets ad y position''<br/><!--GIDEROSMTD:Ads:getY() gets ad y position-->
[[Special:MyLanguage/Ads:set|Ads:set]] ''<translate>sets property value of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:set(property,value) sets property value of the ad -->
+
[[Ads:hideAd]] ''hides ad''<br/><!-- GIDEROSMTD:Ads:hideAd() hides ad-->
[[Special:MyLanguage/Ads:setAlignment|Ads:setAlignment]] ''<translate>sets alignment of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:setAlignment(horizontal,vertical) sets alignment of the ad -->
+
[[Ads:loadAd]] ''loads ad''<br/><!-- GIDEROSMTD:Ads:loadAd() loads ad-->
[[Special:MyLanguage/Ads:setKey|Ads:setKey]] ''<translate>set keys for the framework</translate>''<br/><!-- GIDEROSMTD:Ads:setKey(...) set keys for the framework -->
+
[[Ads:set]] ''sets ad property value''<br/><!--GIDEROSMTD:Ads:set(property,value) sets ad property value-->
[[Special:MyLanguage/Ads:setPosition|Ads:setPosition]] ''<translate>sets position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:setPosition(x,y) sets position of the ad -->
+
[[Ads:setAlignment]] ''sets ad alignment''<br/><!--GIDEROSMTD:Ads:setAlignment(horizontal,vertical) sets ad alignment-->
[[Special:MyLanguage/Ads:setX|Ads:setX]] ''<translate>Sets x position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:setX(x) Sets x position of the ad -->
+
[[Ads:setKey]] ''sets framework key''<br/><!--GIDEROSMTD:Ads:setKey(...) sets framework key-->
[[Special:MyLanguage/Ads:setY|Ads:setY]] ''<translate>sets y position of the ad</translate>''<br/><!-- GIDEROSMTD:Ads:setY(y) sets y position of the ad -->
+
[[Ads:setPosition]] ''sets ad position''<br/><!--GIDEROSMTD:Ads:setPosition(x,y) sets ad position-->
[[Special:MyLanguage/Ads:showAd|Ads:showAd]] ''<translate>display ad</translate>''<br/><!-- GIDEROSMTD:Ads:showAd(...) display ad -->
+
[[Ads:setX]] ''sets ad x position''<br/><!--GIDEROSMTD:Ads:setX(x) sets ad x position-->
 +
[[Ads:setY]] ''sets ad y position''<br/><!--GIDEROSMTD:Ads:setY(y) sets ad y position-->
 +
[[Ads:showAd]] ''displays ad''<br/><!--GIDEROSMTD:Ads:showAd(...) displays ad-->
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
[[Special:MyLanguage/Event.AD_ACTION_BEGIN|Event.AD_ACTION_BEGIN]]<br/><!-- GIDEROSEVT:Event.AD_ACTION_BEGIN adActionBegin-->
+
[[Event.AD_ACTION_BEGIN]]<br/><!--GIDEROSEVT:Event.AD_ACTION_BEGIN adActionBegin-->
[[Special:MyLanguage/Event.AD_ACTION_END|Event.AD_ACTION_END]]<br/><!-- GIDEROSEVT:Event.AD_ACTION_END adActionEnd-->
+
[[Event.AD_ACTION_END]]<br/><!--GIDEROSEVT:Event.AD_ACTION_END adActionEnd-->
[[Special:MyLanguage/Event.AD_DISMISSED|Event.AD_DISMISSED]]<br/><!-- GIDEROSEVT:Event.AD_DISMISSED adDismissed-->
+
[[Event.AD_CONSENT]]<br/><!--GIDEROSEVT:Event.AD_CONSENT adConsent-->
[[Special:MyLanguage/Event.AD_ERROR|Event.AD_ERROR]]<br/><!-- GIDEROSEVT:Event.AD_ERROR adError-->
+
[[Event.AD_DISMISSED]]<br/><!--GIDEROSEVT:Event.AD_DISMISSED adDismissed-->
[[Special:MyLanguage/Event.AD_FAILED|Event.AD_FAILED]]<br/><!-- GIDEROSEVT:Event.AD_FAILED adFailed-->
+
[[Event.AD_DISPLAYED]]<br/><!--GIDEROSEVT:Event.AD_DISPLAYED adDisplayed-->
[[Special:MyLanguage/Event.AD_RECEIVED|Event.AD_RECEIVED]]<br/><!-- GIDEROSEVT:Event.AD_RECEIVED adReceived-->
+
[[Event.AD_ERROR]]<br/><!--GIDEROSEVT:Event.AD_ERROR adError-->
=== <translate>Constants</translate> ===
+
[[Event.AD_FAILED]]<br/><!--GIDEROSEVT:Event.AD_FAILED adFailed-->
 +
[[Event.ADS_READY]]<br/><!--GIDEROSEVT:Event.ADS_READY adsReady-->
 +
[[Event.AD_RECEIVED]]<br/><!--GIDEROSEVT:Event.AD_RECEIVED adReceived-->
 +
[[Event.AD_REWARDED]]<br/><!--GIDEROSEVT:Event.AD_REWARDED adRewarded-->
 +
 
 +
=== Constants ===
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 04:30, 16 February 2025

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