Vanilla JS
1. Insert widget code in the app
You can integrate the widget using native JavaScript. Add the following code to your project, ensuring that the tads script is loaded beforehand:
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
Replace YOUR_WIDGET_ID with the corresponding widget ID you received from your personal account.
3. Set a reward (if needed)
If you want to incentivize users to view or click on the ads, add code to the onShowRewardCallback
and onClickRewardCallback
and onAdsNotFound
functions to reward the user for viewing and/or clicking, respectively.
You can config your widget using the following parameters
id
required
string
Your widget ID that you received from your personal account
type
required
string
static
Type of your widget. It can be 'static' or 'fullscreen'
debug
optional
boolean
false
Flag which you can use for development mode (it doesn't collect data in your ads account and doesn't requests real ads)
onShowReward
optional
function
null
Callback which will be called after user watches ad
onClickReward
optional
function
null
Callback which will be called after user clicks ad
onAdsNotFound
optional
function
null
Callback which will be called if we don't find ads for user
Last updated