Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Last active June 14, 2021 08:10
Show Gist options
  • Select an option

  • Save scottopolis/1b4c0792ebebfe9722533e769a5a7131 to your computer and use it in GitHub Desktop.

Select an option

Save scottopolis/1b4c0792ebebfe9722533e769a5a7131 to your computer and use it in GitHub Desktop.
Sample Javascript to show an interstitial ad in an AppPresser app
// https://docs.apppresser.com/article/515-interstitial-ads
(function() {
// show an interstitial when an element with an id of showAd is clicked. For example, add this to your app:
// <button ion-item id="showAd" (click)="pushPage( pages.tab_menu.items[1] )"><ion-icon name="cog" item-left></ion-icon>Show ad and navigate</button>
// you can use any element with the id of showAd, it doesn't have to be a button
// you can also load the interstitial when the app loads by moving it outside the ready function
ready("#showAd", function(element) {
var el = document.getElementById("showAd");
var adunit;
var userAgent = navigator.userAgent;
if (/android/i.test(userAgent)) {
// put android ad unit ID here
adunit = "ca-app-pub-XXXXXXXXXXXXXXXXX123"
}
if (/iPad|iPhone|iPod/.test(userAgent) ) {
// put iOS ad unit id here
adunit = "ca-app-pub-XXXXXXXXXXXXXXXXX456"
}
if (AdMob) {
AdMob.prepareInterstitial({
adId: adunit,
autoShow: false
});
}
el.addEventListener("click", function() {
console.log('clicked show ad', AdMob);
// show the interstitial later, e.g. at end of game level
if (AdMob) AdMob.showInterstitial();
});
});
})();
@mahnooraslam
Copy link

Can you reply, please?
The code doesn't work

did you find the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment