Advertisements
Monetize your app with Google AdMob
Overview
Ad types available
AdMob Required
Enable AdMob in your dashboard and configure your App ID and Ad Unit IDs.
Banner Ads
Small ads at screen edge. Non-intrusive.
Interstitial Ads
Full-screen ads at transition points.
Rewarded Ads
Users watch for rewards. Highest revenue.
Banner Ads
Always-visible ads
shift2appjs.showBannerAd()
Displays banner ad at configured position (top or bottom).
Returns
void
// Show banner on page load
if (typeof shift2appjs !== "undefined") {
shift2appjs.showBannerAd();
}
shift2appjs.hideBannerAd()
Hides the banner ad.
Returns
void
// Hide on checkout pages
if (location.pathname.includes("/checkout")) {
shift2appjs.hideBannerAd();
}
Interstitial Ads
Full-screen ads
shift2appjs.showInterstitialAd(callbackName)
Shows full-screen interstitial ad. Callback invoked when closed.
Parameters
callbackName
String - Global function name to call when ad closes
Returns
void
// Define callback
function onAdClosed(shown) {
console.log(shown ? "Ad shown" : "Ad failed");
loadNextPage();
}
// Show ad
shift2appjs.showInterstitialAd("onAdClosed");
shift2appjs.isInterstitialAdReady()
Checks if an interstitial ad is loaded and ready.
Returns
Boolean - true if ready
// Only show if ready
if (shift2appjs.isInterstitialAdReady()) {
shift2appjs.showInterstitialAd("onAdClosed");
} else {
loadNextPage(); // Skip ad
}
Rewarded Ads
Users watch for rewards
shift2appjs.showRewardedAd(callbackName)
Shows rewarded video ad. Callback receives reward info when user finishes watching.
Parameters
callbackName
String - Global function to receive reward data
Returns
void
// Define reward callback
function onRewardEarned(success, amount, type) {
if (success) {
alert("You earned " + amount + " " + type + "!");
addCoinsToUser(amount);
} else {
alert("Watch complete video for reward!");
}
}
// Offer to user
if (shift2appjs.isRewardedAdReady()) {
if (confirm("Watch video for 50 coins?")) {
shift2appjs.showRewardedAd("onRewardEarned");
}
}
shift2appjs.isRewardedAdReady()
Checks if a rewarded ad is loaded and ready.
Returns
Boolean - true if ready
// Update button state
function updateRewardButton() {
const btn = document.getElementById("watchAdBtn");
btn.disabled = !shift2appjs.isRewardedAdReady();
btn.textContent = btn.disabled ? "Loading..." : "Watch Ad for Coins";
}
setInterval(updateRewardButton, 5000);
Best Practices
Show ads at natural breaks
Between articles, levels, or after completing actions.
Give meaningful rewards
Coins, extra features, or premium content users actually want.
Don't spam interstitials
Limit to once every 2-3 minutes. Users will uninstall if annoyed.
Don't force rewarded ads
Always make them optional. Users should choose to watch.