Ads3Ads3
How Ad Network Works
Advertiser
Publisher
  • Telegram
  • Twitter
  • Discord
  • Press Kit
  • English
  • 简体中文
How Ad Network Works
Advertiser
Publisher
  • Telegram
  • Twitter
  • Discord
  • Press Kit
  • English
  • 简体中文
  • Publisher

  • Get Started

    • Introduction
    • Get BlockId
    • Ad Integration Examples
  • Code Integration

    • Publisher Integration Checklist
    • SDK Integration for Native Ads
    • SDK Integration for Rewarded Ads
  • Reference

    • Code Examples
    • SDK Installation
    • Data Analysis and Revenue Settlement
    • Technical Manual

      • SDK API Reference
      • User Profile
      • API Ad Integration
    • Getting App Id
    • Glossary

SDK Ad Integration - Rewarded Ads

Prerequisites

  • Know where to display ads. If not, please see Ad Integration Examples.
  • Have obtained the BlockId. If not, please see Get BlockId.
  • Refer to SDK Installation to learn how to install the SDK.

Rewarded Ads

Users can earn rewards after clicking "Watch Ad", for example:

watch_ad
watch_ad

Execute the following code:

import { TonAdPopupShow } from 'ton-ai-sdk'

TonAdPopupShow({
  blockId: 'your_block_id',
  countdown: 15,  // Optional, default is 10 seconds, minimum is 10 seconds, maximum is 30 seconds
  autoClose: true, // Default is true, meaning the ad automatically closes after the countdown
  onAdComplete: (ad) => {
    // User finished watching the ad, reward can be given here
    // sendReward(ad)
  },
  onAdClick: (ad) => {
    // User clicked on the ad, reward can be given here
    // sendReward(ad)
  },
  onAdError: (error) => {
    // User encountered an error while watching the ad
    console.error(error)
  },
  onAdClose: (ad) => {
    // User manually closed the ad
  }
})

Based on your product design, choose the appropriate timing to send rewards.

  • onAdComplete: Relevant for CPM model, meaning the user gets a reward after watching the ad completely.
  • onAdClick: Relevant for CPC model, where users get a reward only when they click the ad.

The ad object returned during each event looks like this:

{
      "adId": "string", // Ad ID
      "adBlockId": "string", // Ad Block ID
      "adFormat": "string", //"image" | "video",
      "icon": "string", // Advertiser's icon
      "text": "string", // Ad text
      "buttonText": "string", // Button text
      "url": "string", // Ad redirect link
}

Tips

If you want the logic for issuing rewards to be handled on the backend, refer to the reward-webhook section in getBlockId.

Tips

Potential reasons for onAdError might include:

  • Network error while fetching the ad
  • Error during ad playback
  • No available ads at the moment

Ad Effect

ad_popup
ad_popup

Click here to view the full sample code

Prev
SDK Integration for Native Ads