SDK Ad Integration
Prerequisites
- Have a clear idea of where to display ads. If not, please check the Ad Integration Examples.
- Already obtained a BlockId. If not, please refer to Get BlockId.
- Refer to SDK Installation for guidance on how to install the SDK.
Displaying Ads
When users click the "Watch Ad" button, proceed with the following code:
import { TonAdPopupShow } from 'ton-ai-sdk'
TonAdPopupShow({
blockId: 'your_block_id',
onAdClick: (ad) => {
// User has clicked on the ad
// You can distribute rewards here
},
onAdError: (error) => {
// Error encountered while the ad was playing
// You can choose to do nothing here, or any action you prefer
},
})
Tips
Within the onAdClick
function, you can distribute rewards, like adding lives or enhancing character strength.
Tips
Possible reasons for errors:
- Network errors while fetching ads
- Errors during ad playback
- No ads available at the moment
Ad Display:
After the ad countdown finishes, various callback functions will be triggered. You can choose to distribute rewards or perform other actions then.