Skip to main content

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:

PriorityPlatformCondition
1CrazyGamesdocument.referrer or parent hostname contains crazygames.com
2Playgama?platform_id=playgama, referrer, or parent hostname contains playgama.com
3Google H5 Games AdsFallback
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

SymptomFix
Ads not showingConfirm Google H5 <script> tags are in HTML
areAdsReady() falseGoogle Ads SDK did not initialize — check script tags and ad blocker
Wrong platform detectedEnable debug: hyve.configureAds({ debug: true })