Ads
Rewarded, interstitial, and preroll ads with automatic platform routing.
Setup
Configure via HyveSdkProvider:
<HyveSdkProvider config={{
ads: {
sound: 'on',
onBeforeAd: (type) => pauseGame(),
onAfterAd: (type) => resumeGame(),
onRewardEarned: () => grantReward(),
}
}}>
Or configure after construction:
hyve.configureAds({ sound: 'off', debug: true });
HTML Setup (Google H5 Ads)
Required in your index.html for the Google H5 fallback:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
window.adBreak = window.adBreak || function(o) { (window.adsbygoogle = window.adsbygoogle || []).push(o); };
window.adConfig = window.adConfig || function(o) { (window.adsbygoogle = window.adsbygoogle || []).push(o); };
</script>
Showing Ads
const result = await hyve.showAd('rewarded'); // user opts in for reward
const result = await hyve.showAd('interstitial'); // between levels / game over
const result = await hyve.showAd('preroll'); // at game start
if (result.success) {
// grant reward, resume game, etc.
}
interface AdResult {
success: boolean;
type: 'rewarded' | 'interstitial' | 'preroll';
error?: Error;
requestedAt: number;
completedAt: number;
}
Platform Routing
showAd() auto-routes in priority order:
| Priority | Platform | Condition |
|---|---|---|
| 1 | CrazyGames | document.referrer or parent hostname contains crazygames.com |
| 2 | Playgama | ?platform_id=playgama, referrer, or parent hostname contains playgama.com |
| 3 | Google H5 Games Ads | Fallback |
hyve.areAdsReady(); // boolean — Google H5 Ads initialized successfully
CrazyGames Signals
CrazyGames requires explicit gameplay start/stop signals. No-ops on all other platforms.
await hyve.gameplayStart(); // call when active gameplay begins
await hyve.gameplayStop(); // call when gameplay pauses (menu, cutscene, level end)
await hyve.happytime(); // trigger celebration for significant achievements
Troubleshooting
| Symptom | Fix |
|---|---|
| Ads not showing | Confirm Google H5 <script> tags are in HTML |
areAdsReady() false | Google Ads SDK did not initialize — check script tags and ad blocker |
| Wrong platform detected | Enable debug: hyve.configureAds({ debug: true }) |