-
Notifications
You must be signed in to change notification settings - Fork 127
Events
Marc Pascual edited this page Jun 16, 2020
·
16 revisions
AdMobAds Cordova library will use the same events for Android as for iOS (the iOS ones are mapped to the Android ones). See Google Docs for more info.
Called when an ad is received.
- event: JSON object.
Example:{ adType : 'banner' }
- adType can be
admob.AD_TYPE.BANNER
oradmob.AD_TYPE.INTERSTITIAL
- adType can be
document.addEventListener(window.admob.events.onAdLoaded, async (ad) => {
if (ad.adType === window.admob.AD_TYPE.BANNER) {
await window.admob.createBannerView( { bannerAdId: 'ca-app-pub-3940256099942544/6300978111' });
await window.admob.showBannerAd();
}
});
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onAdLoaded().subscribe(async (ad: IAdMobEvent) => {
if (ad.adType === this.admob.AD_TYPE.BANNER) {
await this.admob.showBannerAd();
}
});
await this.admob.createBannerView({ bannerAdId: 'ca-app-pub-3940256099942544/6300978111' });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdLoaded', async (ad: IAdMobEvent) => {
if (ad.adType === 'banner') {
await this.adMobAdsPlugin.showBannerAd();
}
});
await this.adMobAdsPlugin.createBannerView({
bannerAdId: 'ca-app-pub-3940256099942544/6300978111',
autoShowBanner: false,
});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdLoaded', async (ad: IAdMobEvent) => {
if (ad.adType === 'banner') {
await this.adMobAdsPlugin.showBannerAd();
}
});
await this.adMobAdsPlugin.createBannerView({
bannerAdId: 'ca-app-pub-3940256099942544/6300978111',
autoShowBanner: false,
});
}
}
import React, { Component } from 'react';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
import { Plugins } from '@capacitor/core';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentDidMount() {
try {
this.adMobAdsPlugin.addListener!('onAdLoaded', async (ad: IAdMobEvent) => {
if (ad.adType === 'banner') {
await this.adMobAdsPlugin.showBannerAd();
}
});
await this.adMobAdsPlugin.createBannerView({
bannerAdId: 'ca-app-pub-3940256099942544/6300978111',
autoShowBanner: false,
});
} catch (err) {
console.log('Error creating banner:', err);
}
}
render() {
return 'your page content';
}
}
Called when an ad request failed.
- event: JSON object.
Example:{ adType : "[string]", error : [integer], reason : "[string]" }
- adType can be admob.AD_TYPE.BANNER or admob.AD_TYPE.INTERSTITIAL
- error is the error code and is usually one of the following:
- AdRequest.ERROR_CODE_INTERNAL_ERROR
- AdRequest.ERROR_CODE_INVALID_REQUEST
- AdRequest.ERROR_CODE_NETWORK_ERROR
- AdRequest.ERROR_CODE_NO_FILL
- reason is an english string with the reason of the error (for logging purposes).
document.addEventListener(window.admob.events.onAdFailedToLoad, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onAdFailedToLoad().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdFailedToLoad', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdFailedToLoad', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onAdFailedToLoad', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when an ad opens an overlay that covers the screen.
Please note that onPause
event is raised when an interstitial is shown.
- event: JSON object.
Example:{ adType : 'banner' }
- adType can be
admob.AD_TYPE.BANNER
oradmob.AD_TYPE.INTERSTITIAL
- adType can be
document.addEventListener(window.admob.events.onAdOpened, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onAdOpened().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdOpened', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdOpened', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onAdOpened', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when the user is about to return to the application after clicking on an ad.
Please note that onResume
event is raised when an interstitial is closed.
- event: JSON object.
Example:{ adType : 'banner' }
- adType can be
admob.AD_TYPE.BANNER
oradmob.AD_TYPE.INTERSTITIAL
- adType can be
document.addEventListener(window.admob.events.onAdClosed, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onAdClosed().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdClosed', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdClosed', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onAdClosed', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when the user has clicked an ad and lefts the current application.
- event: JSON object.
Example:{ adType : 'banner' }
- adType can be
admob.AD_TYPE.BANNER
,admob.AD_TYPE.INTERSTITIAL
oradmob.AD_TYPE.AD_TYPE_REWARDED
- adType can be
document.addEventListener(window.admob.events.onAdLeftApplication, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onAdLeftApplication().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdLeftApplication', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onAdLeftApplication', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onAdLeftApplication', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when the user has earn the reward from a rewarded ad.
- event: JSON object.
Example:{ adType : 'banner' }
- adType is
admob.AD_TYPE.AD_TYPE_REWARDED
- adType is
document.addEventListener(window.admob.events.onRewardedAd, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onRewardedAd().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAd', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAd', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onRewardedAd', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when the rewarded video ad has started.
- event: JSON object.
Example:{ adType : 'banner' }
- adType is
admob.AD_TYPE.AD_TYPE_REWARDED
- adType is
document.addEventListener(window.admob.events.onRewardedAdVideoStarted, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onRewardedAdVideoStarted().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAdVideoStarted', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAdVideoStarted', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onRewardedAdVideoStarted', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}
Called when the rewarded video ad has been completed.
- event: JSON object.
Example:{ adType : 'banner' }
- adType is
admob.AD_TYPE.AD_TYPE_REWARDED
- adType is
document.addEventListener(window.admob.events.onRewardedAdVideoCompleted, ad => { });
import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob, IAdMobEvent } from '@ionic-native/admob';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit(): Promise<void> {
await this.platform.ready();
this.admob.onRewardedAdVideoCompleted().subscribe((ad: IAdMobEvent) => { });
}
}
import { Component } from '@stencil/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css',
shadow: false,
})
export class HomePage {
private adMobAdsPlugin: AdMobAdsPlugin;
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAdVideoCompleted', (ad: IAdMobEvent) => {});
}
}
import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
@Component({
selector: 'app-home-page',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
private adMobAdsPlugin: AdMobAdsPlugin;
async ngOnInit(): Promise<void> {
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
this.adMobAdsPlugin.addListener('onRewardedAdVideoCompleted', (ad: IAdMobEvent) => {});
}
}
import React, { Component } from 'react';
import { Plugins } from '@capacitor/core';
import { AdMobAdsPlugin, IAdMobEvent } from 'admob-capacitor';
export default class HomePage extends Component {
private adMobAdsPlugin: AdMobAdsPlugin;
constructor(props: any) {
super(props);
this.adMobAdsPlugin = Plugins.AdMobAds as AdMobAdsPlugin;
}
async componentWillLoad(): Promise<void> {
this.adMobAdsPlugin.addListener!('onRewardedAdVideoCompleted', (ad: IAdMobEvent) => {});
}
render() {
return 'your page content';
}
}