Allows for the display of AdMob in Titanium Android applications.
Please note that if your androidManifest has screen support set to: android:anyDensity="false", any banner ads will display too small on high density devices. It is not clear at this point if this is a bug with AdMob or Titanium. In any event, you will either need to NOT set your screen support -- or set android:anyDensity="true" and adjust your app layout accordingly
View the Using Titanium Modules document for instructions on getting started with using this module in your application.
For Ti.Android.Admob 5.1.5
- Titanium SDK 7.0.0+
- Ti.PlayServices 16.1.3 module
For Ti.Android.Admob 6.0.3
- Titanium SDK 9.0.0+
https://developers.google.com/mobile-ads-sdk/
All AdViews, except Rewarded, have the parameters keyword and contentUrl and can be used with DFP mapping
You can get it here
First you need to require the module
var admob = require("ti.android.admob");
It is recommended to get users locations before loading any ads in order the show a personalized Ads
if (!Titanium.Geolocation.hasLocationPermissions(Titanium.Geolocation.AUTHORIZATION_ALWAYS)) {
Titanium.API.warn('Location permissions not granted! Asking now...');
Titanium.Geolocation.requestLocationPermissions(Titanium.Geolocation.AUTHORIZATION_ALWAYS, function(e){
if (!e.success) {
Titanium.API.error('Location permissions declined!');
} else {
Titanium.API.info('Location permissions ready');
LoadAds();
}
});
} else {
Titanium.API.warn('Location permissions already granted!');
LoadAds();
}
Types | Description |
---|---|
ADAPTATIVE_BANNER | Drop-in replacement for the industry standard 320x50 banner size, as well as the smart banner format they supersede. |
BANNER | Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels). |
LARGE_BANNER | Large banner ad size (320x100 density-independent pixels). |
SMART_BANNER | A dynamically sized banner that is full-width and auto-height. |
MEDIUM_RECTANGLE | Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels). |
FULLBANNER | Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels). |
LEADERBOARD | Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels). |
FLUID | A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes. |
WIDE_SKYSCRAPER | IAB wide skyscraper ad size (160x600 density-independent pixels). |
SEARCH | A special variant of FLUID to be set on SearchAdView when loading a DynamicHeightSearchAdRequest`. |
var adView = Admob.createView({
bottom : 0,
//keyword : "titanium",
//contentUrl : "www.myur.com",
extras : {
'npa' : '1' //Disable personalized ads
}
viewType : Admob.TYPE_ADS,
adSizeType: Admob.ADAPTATIVE_BANNER,
testDeviceId : "G9CCEHKYF95FFR8152FX50D059DC8336", //USE YOUR DEVICE ID HERE
adUnitId: 'ca-app-pub-3940256099942544/6300978111', //USE YOUR AD_UNIT ID HERE
});
window.add(adView);
adView.addEventListener(Admob.AD_RECEIVED, function(e) {
Titanium.API.info("Ad received");
});
adView.addEventListener(Admob.AD_NOT_RECEIVED, function(e) {
Titanium.API.info("Ad failed");
});
var rewarded = Admob.createView({
viewType : Admob.TYPE_ADS,
adSizeType: Admob.REWARDED_VIDEO,
testDeviceId : "G9CCEHKYF95FFR8152FX50D059DC8336", //USE YOUR DEVICE ID HERE
adUnitId: 'ca-app-pub-3940256099942544/5224354917', //USE YOUR AD_UNIT ID HERE
});
window.add(rewarded);
window.addEventListener("open", function(){
//You can preload the ads at any moment you judge the best
rewarded.loadRewardedAd();
});
rewarded.addEventListener(Admob.AD_RECEIVED, function(e) {
Titanium.API.info("Rewarded Ad AD_RECEIVED");
rewarded.showAdNow();
});
rewarded.addEventListener(Admob.AD_REWARDED, function(e) {
Titanium.API.info("Rewarded Ad AD_REWARDED");
Titanium.API.info("Yay! You can give the user his reward now!");
Titanium.API.info(JSON.stringify(e));
});
rewarded.addEventListener(Admob.AD_OPENED, function(e) {
Titanium.API.info("Rewarded Ad AD_OPENED");
});
rewarded.addEventListener(Admob.AD_VIDEO_STARTED, function(e) {
Titanium.API.info("Rewarded Ad AD_VIDEO_STARTED");
});
var multipleAds = Admob.createView({
top: 0,
viewType : Admob.TYPE_ADS,
adSizes: [
{width: 320, height: 100},
{width: 320, height: 50},
{width: 320, height: 240}
],
testDeviceId : "G9CCEHKYF95FFR8152FX50D059DC8336", //USE YOUR DEVICE ID HERE
adUnitId: 'ca-app-pub-3940256099942544/6300978111', //USE YOUR AD_UNIT ID HERE
});
window.add(multipleAds);
multipleAds.addEventListener(Admob.AD_RECEIVED, function(e) {
Titanium.API.info("Ad received");
});
multipleAds.addEventListener(Admob.AD_NOT_RECEIVED, function(e) {
Titanium.API.info("Ad failed");
});
var interstitialAd = Admob.createView({
viewType : Admob.TYPE_ADS,
adSizeType: Admob.INTERSTITIAL,
testDeviceId : "G9CCEHKYF95FFR8152FX50D059DC8336", //USE YOUR DEVICE ID HERE
adUnitId: 'ca-app-pub-3940256099942544/1033173712', //USE YOUR AD_UNIT ID HERE
});
window.add(interstitialAd);
interstitialAd.addEventListener(Admob.AD_RECEIVED, function(e) {
Titanium.API.warn("Interstital Ad Received");
});
interstitialAd.addEventListener(Admob.AD_NOT_RECEIVED, function(e) {
Titanium.API.error("Interstital Ad failed");
});
interstitialAd.addEventListener(Admob.AD_READY_TO_BE_SHOWN, function(e) {
Titanium.API.warn("Interstital Ad is READY!");
interstitialAd.showAdNow();
});
interstitialAd.addEventListener(Admob.AD_NOT_READY_YET, function(e) {
Titanium.API.warn("Interstital Ad is not ready yet!");
});
interstitialAd.addEventListener(Admob.AD_BEING_SHOWN, function(e) {
Titanium.API.warn("Interstital Ad being shown right now!");
});
interstitialAd.addEventListener(Admob.AD_CLOSED, function(e) {
Titanium.API.warn("Interstital ad close successfully. RIP!");
interstitialAd.requestInterstitalAd();
});
var masterView = Titanium.UI.createView({
width : Titanium.UI.FILL,
height : Titanium.UI.SIZE,
layout : "vertical"
});
var topView = Titanium.UI.createView({
top : 0,
left : 0,
right : 0,
height : Titanium.UI.SIZE,
layout : "horizontal"
});
masterView.add(topView);
var contentad_logo = Titanium.UI.createImageView({
elevation : 12,
height : 50
});
topView.add(contentad_logo);
var contentad_advertiser = Titanium.UI.createLabel({
color : "#575757",
left : 16,
textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT,
verticalAlign : Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER,
height : 35,
font : {
fontSize : 18,
fontWeight : "bold"
}
});
topView.add(contentad_advertiser);
var mediaView = Admob.createView({
viewType : Admob.TYPE_MEDIA,
top : 0,
left : 0,
right : 0,
height : 250
});
masterView.add(mediaView);
var contentad_headline = Titanium.UI.createLabel({
top : 16,
maxLines : 2,
color : "#000000",
left : 16,
right : 16,
textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT,
font : {
fontSize : 20,
f ontWeight : "bold"
}
});
masterView.add(contentad_headline);
var contentad_body = Titanium.UI.createLabel({
color : "#575757",
left : 16,
right : 16,
textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT,
font : {
f ontSize : 16
}
});
masterView.add(contentad_body);
var contentad_call_to_action = Titanium.UI.createButton({
top : 16,
elevation : 8,
right : 16,
width : Titanium.UI.SIZE,
height : 35,
backgroundColor : "#ff5722",
font : {
fontSize : 14,
fontWeight : "bold"
}
});
masterView.add(contentad_call_to_action);
var ratingView = Admob.createView({
viewType : Admob.TYPE_STARS,
left : 0,
right : 0
});
masterView.add(ratingView);
var contentad_store_view = Titanium.UI.createLabel({
color : "#D50000",
top : 8,
font : {
fontSize : 16
}
});
masterView.add(contentad_store_view);
var contentad_price_view = Titanium.UI.createLabel({
color : "#575757",
height : Titanium.UI.SIZE,
width : Titanium.UI.SIZE,
font : {
fontSize : 12
}
});
masterView.add(contentad_advertiser);
var nativeAd = Admob.createView({
//Standard Widgets
masterView : masterView,
headlineLabel : contentad_headline,
bodyLabel : contentad_body,
callToActionButton : contentad_call_to_action,
logoOrIconImageView : contentad_logo,
advertiserLabel : contentad_advertiser,
mediaView : mediaView,
//Store Widgets
storeLabel : contentad_store_view,
starsView : ratingView,
priceLabel : contentad_price_view,
top : 16,
left : 16,
right : 16,
height : Titanium.UI.SIZE,
backgroundColor : "#FFFFFF",
viewType : Admob.TYPE_ADS,
adSizeType: Admob.UNIFIED_NATIVE_ADS,
adUnitId : "ca-app-pub-3940256099942544/2247696110",
testDeviceId : "E6BB08637D19DA5B1C7BBA4758FC0F95",
});
window.add(nativeAd);
nativeAd.addEventListener(Admob.AD_RECEIVED, function(e) {
Titanium.API.info("Native Ad received");
});
nativeAd.addEventListener(Admob.AD_NOT_RECEIVED, function(e) {
Titanium.API.info("Native Ad failed");
});
Events | Description |
---|---|
AD_RECEIVED | Ad have been successfully received |
AD_NOT_RECEIVED | A error occurred and the ads failed |
AD_DESTROYED | Ad had been successfully destroyed and wiped out of memory |
AD_READY_TO_BE_SHOWN | (INTERSTITIAL) The ad is ready and can be shown |
AD_NOT_READY_YET | (INTERSTITIAL) If you try to show the interstitial ad before it is ready, this event will fire |
AD_BEING_SHOWN | (INTERSTITIAL) Ad is on screen |
AD_CLOSED | (REWARDED or INTERSTITIAL) Ad had been successfully closed |
AD_OPENED | (REWARDED) Ad is now on screen and visible |
AD_REWARDED | (REWARDED) When the video ended successfully and you can reward you user with his prize |
AD_VIDEO_STARTED | (REWARDED) When the rewarded video starts playing |
Returns a number value indicating the availability of Google Play Services which are for push notifications.
Possible values include SUCCESS
, SERVICE_MISSING
, SERVICE_VERSION_UPDATE_REQUIRED
, SERVICE_DISABLED
,
and SERVICE_INVALID
.
Requests consent information update for the provided publisher identifiers. All publisher identifiers used in the application should be specified in this call. Consent status is reset to unknown when the ad provider list changes.
publisherIdentifiers
(Array)callback
(Function)
Shows a consent modal form. Arguments:
shouldOfferPersonalizedAds
(Boolean) Indicates whether the consent form should show a personalized ad option. Defaults totrue
.shouldOfferNonPersonalizedAds
(Boolean) Indicates whether the consent form should show a non-personalized ad option. Defaults totrue
.shouldOfferAdFree
(Boolean) Indicates whether the consent form should show an ad-free app option. Defaults tofalse
.callback
(Function) Callback to be triggered once the form completes.
Resets consent information to default state and clears ad providers.
Sets whether the user is tagged for under age of consent.
Indicates whether the user is tagged for under age of consent.
consentStatus
(CONSENT_STATUS_UNKNOWN
, CONSENT_STATUS_NON_PERSONALIZED
or CONSENT_STATUS_PERSONALIZED
)
Array of ad providers.
Debug geography. Used for debug devices only.
Gets the user Android Advertising ID. Since this works in a background thread in native
Android a callback is called when the value is fetched. The callback parameter is a key/value
pair with key androidAdId
and a String value with the id.
Admob.getAndroidAdId(function (data) {
Ti.API.info('AAID is ' + data.aaID);
});
Checks whether the user has opted out from ad tracking in the device's settings. Since
this works in a background thread in native Android a callback is called when the value
is fetched. The callback parameter is a key/value pair with key isLimitAdTrackingEnabled
and a boolean value for the user's setting.
Admob.isLimitAdTrackingEnabled(function (data) {
Ti.API.info('Ad tracking is limited: ' + data.isLimitAdTrackingEnabled);
});
Starting in 4.3.0 you can use the included Facebook Audience Network adapter to turn on the mediation in your AdMob account. Here you do not have to do anything ๐. You only need to configure mediation in your AdMob and Facebook accounts by following the official guide.
Returned by isGooglePlayServicesAvailable()
if the connection to Google Play Services was successful.
Returned by isGooglePlayServicesAvailable()
if Google Play Services is missing on this device.
Returned by isGooglePlayServicesAvailable()
if the installed version of Google Play Services is out of date.
Returned by isGooglePlayServicesAvailable()
if the installed version of Google Play Services has been disabled on this device.
Returned by isGooglePlayServicesAvailable()
if the version of the Google Play Services installed on this device is not authentic.
Returned by consentStatus
if the consent status is unknown.
Returned by consentStatus
if the consent status is not personalized.
Returned by consentStatus
if the consent status is personalized.
Returned by debugGeography
if geography debugging is disabled.
Returned by debugGeography
if geography appears as in EEA for debug devices.
Returned by debugGeography
if geography appears as not in EEA for debug devices.
Events | Description |
---|---|
Adaptative Banner | ca-app-pub-3940256099942544/9214589741 |
Banner | ca-app-pub-3940256099942544/6300978111 |
Interstitial | ca-app-pub-3940256099942544/1033173712 |
Interstitial Video | ca-app-pub-3940256099942544/8691691433 |
Rewarded Video | ca-app-pub-3940256099942544/5224354917 |
Unified Native | ca-app-pub-3940256099942544/2247696110 |