Vanilla JS
1. Insert widget code in the app
You can also integrate the widget using native JavaScript. Add the following code to your project, ensuring that the tads script is loaded beforehand:
Insert the following script into <head> or in the end of <body> in your HTML document:
<script src="https://w.tads.me/widget.js"></script>
Insert the following
<div>
where you want to render the ad:
<div id="tads-container-YOUR_WIDGET_ID"></div>
Add the following code to your HTML document to initialize the widget:
<script>
const adsNotFoundCallback = () => {
console.log('No ads found to show');
// Write your code here in case we couldn't display ad
};
// Callbacks for REWARDED format
const onClickRewardCallback = (adId) => {
console.log('Clicked ad:', adId);
};
const onShowRewardCallback = (adId) => {
console.log(Showed ad: ', adId);
};
const adController = window.tads.init({
widgetId: YOUR_WIDGET_ID,
type: 'static',
debug: false, // Use 'true' for development and 'false' for production
onShowReward: onShowRewardCallback,
onClickReward: onClickRewardCallback,
onAdsNotFound: adsNotFoundCallback
});
adController.loadAd()
.then(() => adController.showAd())
.catch((err) => {
console.log(err);
adsNotFoundCallback();
});
</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 see all configuration parameters in our npm-package
Last updated