Last active
June 14, 2021 08:10
-
-
Save scottopolis/1b4c0792ebebfe9722533e769a5a7131 to your computer and use it in GitHub Desktop.
Sample Javascript to show an interstitial ad in an AppPresser app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); | |
}); | |
})(); |
Can you reply, please?
The code doesn't work
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
Hi Scott
Thank you for the code.
Did it work for you?
I have been trying to trigger an ad on app launch according to your instructions but it didn't work.
May I have the exact code you added to trigger ad on app launch?
Here are a few examples (without ad ids) of what I've tried so far:
https://codeshare.io/GLYOYe
https://codeshare.io/arJwJE
https://codeshare.io/ay9b99
https://codeshare.io/2jbYbg
Here's two screenshots from debugging:
https://ibb.co/m03qwmd
https://ibb.co/JkRV7pV