2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
import { Cordova , Plugin } from '@ionic-native/core' ;
2016-09-21 15:04:46 -05:00
import { Observable } from 'rxjs/Observable' ;
2016-04-29 17:17:30 -04:00
2017-03-20 16:38:14 -04:00
export type AdSize = 'SMART_BANNER' | 'BANNER' | 'MEDIUM_RECTANGLE' | 'FULL_BANNER' | 'LEADERBOARD' | 'SKYSCRAPER' | 'CUSTOM' ;
2016-12-06 08:29:39 -05:00
export interface AdMobOptions {
2016-12-22 10:15:49 -08:00
/**
* Banner ad ID
*/
adId? : string ;
2016-12-06 08:29:39 -05:00
/**
* Banner Ad Size, defaults to `SMART_BANNER`. IT can be: `SMART_BANNER`, `BANNER`, `MEDIUM_RECTANGLE`, `FULL_BANNER`, `LEADERBOARD`, `SKYSCRAPER`, or `CUSTOM`
*/
2017-03-20 16:38:14 -04:00
adSize? : AdSize ;
2016-12-06 08:29:39 -05:00
/**
* Banner width, valid when `adSize` is set to `CUSTOM`
*/
width? : number ;
/**
* Banner height, valid when `adSize` is set to `CUSTOM`
*/
height? : number ;
/**
* Allow banner to overlap webview, or else it will push webview up or down to avoid overlap. Defaults to false.
*/
overlap? : boolean ;
/**
* Position of banner ad. Defaults to `TOP_CENTER`. You can use the `AdMob.AD_POSITION` property to select other values.
*/
position? : number ;
/**
* X in pixels. Valid when `position` is set to `POS_XY`
*/
x? : number ;
/**
* Y in pixels. Valid when `position` is set to `POS_XY`
*/
y? : number ;
/**
* Set to true to receive test ad for testing purposes
*/
isTesting? : boolean ;
/**
* Auto show interstitial ad when loaded. Set to false if hope to control the show timing with prepareInterstitial/showInterstitial
*/
autoShow? : boolean ;
/**
* Re-create the banner on web view orientation change (not screen orientation), or else just move the banner. Default:true.
*/
orientationRenew? : boolean ;
/**
* Set extra color style for Ad
*/
2017-03-20 16:38:14 -04:00
adExtras? : AdExtras ;
2016-12-06 08:29:39 -05:00
}
2017-03-20 16:38:14 -04:00
export interface AdExtras {
2016-12-06 08:29:39 -05:00
color_bg : string ;
color_bg_top : string ;
color_border : string ;
color_link : string ;
color_text : string ;
color_url : string ;
}
2016-04-29 17:17:30 -04:00
/**
* @name AdMob
2016-12-06 08:29:39 -05:00
* @description
* Plugin for Google Ads, including AdMob / DFP (doubleclick for publisher) and mediations to other Ad networks.
2016-04-29 17:17:30 -04:00
* @usage
2016-11-03 10:41:41 +01:00
* ```typescript
2017-03-20 16:38:14 -04:00
* import { AdMob, AdMobOptions, AdSize, AdExtras } from '@ionic-native/ad-mob';
*
* constructor(private admob: AdMob){}
2016-12-06 08:02:00 -05:00
*
2016-11-03 10:41:41 +01:00
* ionViewDidLoad() {
2017-03-20 16:38:14 -04:00
* this.admob.onAdDismiss()
2016-12-06 08:29:39 -05:00
* .subscribe(() => { console.log('User dismissed ad'); });
2016-11-03 10:41:41 +01:00
* }
2016-12-06 08:02:00 -05:00
*
2016-12-06 08:29:39 -05:00
* onClick() {
2017-03-20 16:38:14 -04:00
* this.admob.prepareInterstitial('YOUR_ADID')
* .then(() => { this.admob.showInterstitial(); });
2016-11-03 10:41:41 +01:00
* }
*
* ```
2016-12-06 08:29:39 -05:00
*
* @interfaces
* AdMobOptions
2017-03-20 16:38:14 -04:00
* AdExtras
2016-04-29 17:17:30 -04:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'AdMob' ,
2016-04-29 17:17:30 -04:00
plugin : 'cordova-plugin-admobpro' ,
pluginRef : 'AdMob' ,
2016-06-11 10:46:37 -04:00
repo : 'https://github.com/floatinghotpot/cordova-admob-pro' ,
platforms : [ 'Android' , 'iOS' , 'Windows Phone 8' ]
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2016-04-29 17:17:30 -04:00
export class AdMob {
2017-03-20 16:38:14 -04:00
AD_POSITION : {
NO_CHANGE : number ;
TOP_LEFT : number ;
TOP_CENTER : number ;
TOP_RIGHT : number ;
LEFT : number ;
CENTER : number ;
RIGHT : number ;
BOTTOM_LEFT : number ;
BOTTOM_CENTER : number ;
BOTTOM_RIGHT : number ;
POS_XY : number ;
} = {
2016-12-06 08:29:39 -05:00
NO_CHANGE : 0 ,
TOP_LEFT : 1 ,
TOP_CENTER : 2 ,
TOP_RIGHT : 3 ,
LEFT : 4 ,
CENTER : 5 ,
RIGHT : 6 ,
BOTTOM_LEFT : 7 ,
BOTTOM_CENTER : 8 ,
BOTTOM_RIGHT : 9 ,
POS_XY : 10
} ;
/**
* Create a banner
* @param adIdOrOptions {string | AdMobOptions} Ad ID or Options
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise that resolves when the banner is created
2016-04-29 17:17:30 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
createBanner ( adIdOrOptions : string | AdMobOptions ) : Promise < any > { return ; }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Destroy the banner, remove it from screen.
2016-04-29 17:17:30 -04:00
*/
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
removeBanner ( ) : void { }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Show banner at position
* @param position {number} Position. Use `AdMob.AD_POSITION` to set values.
2016-04-29 17:17:30 -04:00
*/
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
showBanner ( position : number ) : void { }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Show banner at custom position
* @param x {number} Offset from screen left.
* @param y {number} Offset from screen top.
2016-04-29 17:17:30 -04:00
*/
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
showBannerAtXY ( x : number , y : number ) : void { }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Hide the banner, remove it from screen, but can show it later
2016-04-29 17:17:30 -04:00
*/
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
hideBanner ( ) : void { }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Prepare interstitial banner
* @param adIdOrOptions {string | AdMobOptions} Ad ID or Options
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise that resolves when interstitial is prepared
2016-04-29 17:17:30 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
prepareInterstitial ( adIdOrOptions : string | AdMobOptions ) : Promise < any > { return ; }
2016-04-29 17:17:30 -04:00
/**
2016-12-06 08:29:39 -05:00
* Show interstitial ad when it's ready
2016-04-29 17:17:30 -04:00
*/
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
showInterstitial ( ) : void { }
2016-04-29 17:17:30 -04:00
/**
* Prepare a reward video ad
2016-12-06 08:29:39 -05:00
* @param adIdOrOptions {string | AdMobOptions} Ad ID or Options
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise that resolves when the ad is prepared
2016-04-29 17:17:30 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
prepareRewardVideoAd ( adIdOrOptions : string | AdMobOptions ) : Promise < any > { return ; }
2016-04-29 17:17:30 -04:00
/**
* Show a reward video ad
*/
@Cordova ( {
2016-04-29 23:56:49 -04:00
sync : true
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
showRewardVideoAd ( ) : void { }
2016-04-29 17:17:30 -04:00
/**
* Sets the values for configuration and targeting
2016-12-06 08:29:39 -05:00
* @param options {AdMobOptions} Options
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise that resolves when the options have been set
2016-04-29 17:17:30 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
setOptions ( options : AdMobOptions ) : Promise < any > { return ; }
2016-04-29 17:17:30 -04:00
/**
* Get user ad settings
* @returns {Promise<any>} Returns a promise that resolves with the ad settings
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
getAdSettings ( ) : Promise < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-12-06 08:29:39 -05:00
/**
* Triggered when failed to receive Ad
* @returns {Observable<any>}
*/
2016-04-29 17:17:30 -04:00
@Cordova ( {
eventObservable : true ,
2016-12-06 08:29:39 -05:00
event : 'onAdFailLoad'
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
onAdFailLoad ( ) : Observable < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-12-06 08:29:39 -05:00
/**
* Triggered when Ad received
* @returns {Observable<any>}
*/
2016-04-29 17:17:30 -04:00
@Cordova ( {
eventObservable : true ,
2016-12-06 08:29:39 -05:00
event : 'onAdLoaded'
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
onAdLoaded ( ) : Observable < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-12-06 08:29:39 -05:00
/**
* Triggered when Ad will be showed on screen
* @returns {Observable<any>}
*/
2016-04-29 17:17:30 -04:00
@Cordova ( {
eventObservable : true ,
2016-12-06 08:29:39 -05:00
event : 'onAdPresent'
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
onAdPresent ( ) : Observable < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-12-06 08:29:39 -05:00
/**
* Triggered when user click the Ad, and will jump out of your App
* @returns {Observable<any>}
*/
2016-04-29 17:17:30 -04:00
@Cordova ( {
eventObservable : true ,
2016-12-06 08:29:39 -05:00
event : 'onAdLeaveApp'
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
onAdLeaveApp ( ) : Observable < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-12-06 08:29:39 -05:00
/**
* Triggered when dismiss the Ad and back to your App
* @returns {Observable<any>}
*/
2016-04-29 17:17:30 -04:00
@Cordova ( {
eventObservable : true ,
2016-12-06 08:29:39 -05:00
event : 'onAdDismiss'
2016-04-29 17:17:30 -04:00
} )
2017-03-20 16:38:14 -04:00
onAdDismiss ( ) : Observable < any > { return ; }
2016-04-29 17:17:30 -04:00
2016-05-20 16:59:18 -04:00
}