Skip to main content
Version: v1.1

Initialize the SDK

Import the SDK Script

#index.html
[...]
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
// Get the SDK Script in the PremiumAds Publishers Dashboard
// Example
<script src="https://cdn.premiumtag.net/h5/c8b9fda6-ae9a-41f0-9934-20abb9b1dab8.js"></script>
</head>

[...]

Init the SDK

[...]
<script>
PremiumAdsSDK.init().then(() => {
console.log("PremiumAds SDK successfully initialized");

}).catch(() => {
console.log("Initialized, something went wrong, load you game anyway");
// fire your function to continue to game
});
</script>
[...]

Implement interstitial ads

Interstitial ads are used to display fullscreen ads and should be triggered on natural breaks in your game, i.e. whenever the user has shown an intent to continue playing.

[...]
// pause your game here if it isn't already
PremiumAdsSDK.interstitialAds(() => {
// you can pause any background music or other audio here
}).then((success) => {
if (success) {
console.log("PremiumAds: interstitial was displayed");
} else {
console.log("PremiumAds: ad no fill");
}
});
[...]

Implement rewarded ads

Rewarded ads allow for a user to choose to watch a rewarded video ad in exchange for a certain benefit in the game (e.g. more coins, etc.). When using 🎬 rewardedAds() , please make it clear to the player beforehand that they’re about to watch an ad.

[...]
// pause your game here if it isn't already
PremiumAdsSDK.rewardAds(() => {
// you can pause any background music or other audio here
}).then((success) => {
if (success == PremiumAdsSDK.statusRewarded.GRANTED) {
console.log("PremiumAds: rewardAds was displayed");
// video was displayed, give reward
} else {
console.log("PremiumAds: ad no fill");
// video not displayed, should not give reward
}
// if the audio was paused you can resume it here (keep in mind that the function above to pause it might not always get called)
// continue your game here
});
[...]

Full example

<html lang="en">
<head>
<title>PremiumAds H5 Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.premiumtag.net/h5/c8b9fda6-ae9a-41f0-9934-20abb9b1dab8.js?v=1a"></script>
</head>
<body>
<script>
PremiumAdsSDK.init().then(() => {
console.log("PremiumAds SDK successfully initialized");

}).catch(() => {
console.log("Initialized, something went wrong, load you game anyway");
// fire your function to continue to game
});
</script>
<canvas id="gameContainer" height="300px" width="300px"></canvas>
<button id="playButton">Play</button>
<button style="display:none" id="headsButton">Heads</button>
<button style="display:none" id="tailsButton">Tails</button>
<button id="rewardedButton">Rewarded Ads</button>
<script src="game.js"></script>
</body>
</html>