Reputation: 1
I spent four days trying to display admob ads in my Cordova phonegap apps but without luck. I tried many plugins but none of them work. Is there anything i miss? Below are my codes
Index.html
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8" />
<script type="text/javascript" src="index.js" />
<script type="text/javascript" src="cordova_plugins.js" />
</head>
<body>
</body>
</html>
Index.js
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
// Set AdMobAds options:
admob.setOptions({
publisherId: "ca-app-pub-3940256099942544/1033173712", // Required
interstitialAdId: "ca-app-pub-3940256099942544/1033173712", // Optional
});
// Start showing banners (atomatic when autoShowBanner is set to true)
admob.createBannerView();
// Request interstitial (will present automatically when autoShowInterstitial is set to true)
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false)
Upvotes: 0
Views: 151
Reputation: 2460
I personally use cordova-plugin-admob-free as it works as intended and does not ad share like some of the others. The tutorial is pretty straight forward. Also there is no need to use removeEventListener for onDeviceReady, it's unnecessary and it will only ever fire once :)
Upvotes: 2