RewardedAd.init()
Initialize the BZZE Ads SDK with your app credentials and configuration. Call this once when your page/game loads.
Syntax
JavaScript
RewardedAd.init(config)
Parameters
config (Required)
An object containing initialization options:
| Property | Type | Required | Description |
|---|---|---|---|
appId |
string | ✓ Yes | Your app ID from Publisher Dashboard |
apiKey |
string | ✓ Yes | Your API key from Publisher Dashboard |
userId |
string | ✓ Yes | Unique ID for this user |
autoPreload |
boolean | Optional | Auto-preload ads (default: true) |
preloadCount |
number | Optional | Number of ads to preload (default: 1) |
maxAdsPerHour |
number | Optional | Max ads per user per hour (default: 10) |
maxAdsPerDay |
number | Optional | Max ads per user per day (default: 50) |
minTimeBetweenAds |
number | Optional | Min seconds between ads (default: 60) |
gdprApplies |
boolean | Optional | Is user in EU/GDPR region? |
gdprConsent |
boolean | Optional | User gave GDPR consent |
coppaCompliant |
boolean | Optional | App is COPPA compliant |
isChildDirected |
boolean | Optional | Content is child-directed |
lang |
string | Optional | User language (e.g., 'en', 'es') |
country |
string | Optional | User country code (e.g., 'US') |
Callbacks (All Optional)
| Callback | Parameters | Description |
|---|---|---|
onReward |
reward | User earned reward (watched full ad) |
onNoFill |
- | No ads available |
onError |
error | Error occurred |
onAdShown |
- | Ad started playing |
onAdLoaded |
count | Ad preloaded successfully |
onAdClicked |
- | User clicked the ad |
onClose |
- | User closed ad (may not have earned reward) |
Examples
Basic Usage
JavaScript
RewardedAd.init({
appId: "APP_1234567890_abc123",
apiKey: "bzze_xyz789",
userId: "user_12345",
onReward: function(reward) {
console.log('Reward earned!', reward);
grantUserReward(100);
}
});
With Preloading
JavaScript
RewardedAd.init({
appId: "APP_1234567890_abc123",
apiKey: "bzze_xyz789",
userId: "user_12345",
// Preloading config
autoPreload: true,
preloadCount: 2, // Keep 2 ads ready
onAdLoaded: function(count) {
console.log(count + ' ads ready!');
updateAdButton(true); // Enable button
},
onReward: function(reward) {
grantUserReward(100);
}
});
With GDPR Compliance
JavaScript
// After showing consent popup to EU users
const userConsent = getUserConsentChoice(); // true/false
RewardedAd.init({
appId: "APP_1234567890_abc123",
apiKey: "bzze_xyz789",
userId: "user_12345",
// GDPR compliance
gdprApplies: true, // User is in EU
gdprConsent: userConsent, // User's choice
onReward: function(reward) {
grantUserReward(100);
}
});
Complete Configuration
JavaScript
RewardedAd.init({
// Required
appId: "APP_1234567890_abc123",
apiKey: "bzze_xyz789",
userId: "user_12345",
// Preloading
autoPreload: true,
preloadCount: 2,
// Frequency capping
maxAdsPerHour: 10,
maxAdsPerDay: 50,
minTimeBetweenAds: 60,
// GDPR/COPPA
gdprApplies: isEUUser(),
gdprConsent: hasUserConsent(),
coppaCompliant: false,
isChildDirected: false,
// Context
lang: 'en',
country: 'US',
// Callbacks
onReward: function(reward) {
console.log('✅ Reward earned!');
addCoins(100);
},
onAdLoaded: function(count) {
console.log('📦 ' + count + ' ads preloaded');
enableAdButton();
},
onAdShown: function() {
console.log('📺 Ad is playing');
pauseGameAudio();
},
onAdClicked: function() {
console.log('🖱️ User clicked ad');
},
onClose: function() {
console.log('❌ Ad closed');
resumeGameAudio();
},
onNoFill: function() {
console.log('😔 No ads available');
showMessage('No ads right now');
},
onError: function(error) {
console.error('🚨 Error:', error);
if (error.code === 'RATE_LIMIT_EXCEEDED') {
showMessage('Wait ' + error.remainingSeconds + 's');
} else {
showMessage('Something went wrong');
}
}
});
Return Value
undefined - This method doesn't return anything.
Notes
- Call once: Only call
init()once per page load - Before showAd(): Must call
init()beforeshowAd() - User ID format: Can be any unique string (avoid PII)
- Frequency caps: Enforced both client and server-side
- GDPR: Required for EU users, optional otherwise
💡 Pro Tip: Store your
appId and apiKey in environment variables, not hardcoded in source code.
See Also
- RewardedAd.showAd() - Show an ad
- Callbacks Reference - All callback details
- GDPR Compliance - GDPR implementation guide