Ads API Integration
Learn how to prepare your HTML5 games for ForgeByte GameHub's advertising system to unlock monetization potential and special rewards.
Why integrate?
Integrating our Ads API allows your game to communicate with the GameHub container. By triggering ads at natural break points, you help support the platform while becoming eligible for our Creator Incentive Program.
Implementation Guide
The app listens on a JavaScript channel named GameHubAds. You can send messages to this channel using GameHubAds.postMessage(JSON.stringify(data)). To ensure your game logic pauses during ads, define the pause/resume callbacks below.
1. Triggering an Interstitial Ad
Triggers a full-screen interstitial ad. Call this between levels or game rounds.
GameHubAds.postMessage(JSON.stringify({
"action": "showInterstitial",
"result": "win" // Optional: "win", "loss", or custom string
}));
2. Triggering a Rewarded Ad
Triggers a rewarded video ad. Define a global onRewarded() function to handle the prize.
GameHubAds.postMessage(JSON.stringify({
"action": "showRewarded"
}));
// Your reward logic:
function onRewarded() {
console.log("User earned reward!");
// Give extra life or currency
}
3. Pausing & Callbacks
When an ad starts, the GameHub container notifies your game via callbacks. To ensure your game logic (physics, animations, and audio) pauses during the ad, define these global functions in your game code:
function onGamePaused() {
console.log("Game paused! Physics stopped.");
// e.g., gameState = 'PAUSED';
}
function onGameResumed() {
console.log("Game resumed! Ready to play.");
// e.g., gameState = 'PLAYING';
}
Rewards & Prizes
Creators who correctly implement the Ads API and maintain high engagement rates may become eligible for:
- Cash Prizes: Monthly payouts for top-performing games.
- Featured Status: Increased visibility in the Community Hub.