Vanilla JS
1. Insert widget code in the app
1
2
3
Add the following code for the selected format to your HTML document to initialize the widget:
Text-Graphic Block (TGB)
<script>
const adsNotFoundCallback = () => {
console.log('No ads found to show');
// Write your code here in case we couldn't display ad
};
// Callback for REWARDED format
const onClickRewardCallback = (adId) => {
console.log('Clicked ad:', adId);
};
const adController = window.tads.init({
widgetId: YOUR_WIDGET_ID,
type: 'static',
debug: false, // Use 'true' for development and 'false' for production
onClickReward: onClickRewardCallback,
onAdsNotFound: adsNotFoundCallback
});
adController.loadAd()
.then(() => adController.showAd())
.catch((err) => {
console.log(err);
adsNotFoundCallback();
});
</script>Fullscreen banner
<script>
document.addEventListener("DOMContentLoaded", function() {
const WIDGET_ID = "your_widget_id";
// Use 'true' for development and 'false' for production
const IS_DEBUG = true;
// The HTML element ID that triggers the display of ads on click.
const btnIdSelector = "your_clickable_selector";
// Callback for REWARDED format.
const onShowRewardCallback = (result) => {
console.log('Show ads, reward user:', result);
};
// Callback for no ads response
const onAdsNotFound = () => {
console.log('Callback which calls if no ads found to show',);
}
const adController = window.tads.init({
widgetId: WIDGET_ID,
type: 'fullscreen',
debug: IS_DEBUG,
onShowReward: onShowRewardCallback,
onAdsNotFound: onAdsNotFound,
});
// Use your button or link HTML selector for getElementById
document.getElementById(btnSelector).addEventListener('click', () => {
adController
.then(() => adController.showAd())
.catch((result) => {
console.log(result);
});
});
});
</script>2. Add your widget ID
3. Set a reward (if needed)
Parameter
Type
Default
Description
Last updated