I am new to Ionic Capacitor and only use VanillaJS. I am trying to incorporate admob ads in my app using capacitor-community/admob.
The app includes a script module to initialize AdMob:
import { AdMob } from ‘@capacitor-community/admob’;
export async function initialize(): Promise {
const { status } = await AdMob.trackingAuthorizationStatus();
AdMob.initialize({
requestTrackingAuthorization: false,
testingDevices: [’’],
initializeForTesting: true
});
}
import { AdMob, BannerAdOptions, BannerAdSize, BannerAdPosition, BannerAdPluginEvents, AdMobBannerSize } from ‘@capacitor-community/admob’;
export async function banner(): Promise {
AdMob.addListener(BannerAdPluginEvents.Loaded, () => {
// Subscribe Banner Event Listener
});
AdMob.addListener(BannerAdPluginEvents.SizeChanged, (size: AdMobBannerSize) => {
// Subscribe Change Banner Size
});
const options: BannerAdOptions = {
adId: 'ca-app-pub-5945756152961868/4894006670',
adSize: BannerAdSize.BANNER,
position: BannerAdPosition.BOTTOM_CENTER,
margin: 0,
isTesting: true
// npa: true
};
AdMob.showBanner(options);
}
-
Any use of AdMob in the javascript code causes an error and the app stops working. Why is the AdMob class not available?
-
For the banner exports above, can an example of the code for the Subscribes be provided?