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

API Ad Integration

If you want to seamlessly integrate ads into your application without obvious pop-ups or banners, you can achieve it through API.

Warning

This method involves a high integration cost. Please use it cautiously and consider using SDK ad integration whenever possible.

This feature is currently in the testing phase, available to a select group of users, and may be removed in future versions.

Tips

Ensure to perform ad retrieval and reporting on the frontend, so the system can access the visiting user's IP for ad region matching.

Prerequisites

  • Decide where to display the ads. If unsure, check the ad integration examples.
  • Obtain a BlockId. If you don't have one, refer to Get BlockId.

1. Retrieve Ad API

API Description

This API is used to obtain ad information, which you need to embed into your product.

Tips

In the production environment, an ad will not be shown again to a user within 10 minutes after a click.

This restriction does not apply in test environments.

Tips

It is recommended to fetch multiple ads at once and display them simultaneously to improve click-through rates.

Request Method

GET https://app.ton.ai/api/v2/openapi/matching/ad

Request Parameters

Parameter NameLocationTypeRequiredDescription
adBlockIdquerystringYesAd spot ID, obtained from Platform -> Ad Spot -> ID
openIdquerystringYesUser's unique identifier
typequerystringYesType corresponding to openId, currently only 'telegram'
limitquerynumberYesLimit on number of ads returned at once, must be >0 and <10
x-api-keyheaderstringYesAPI Key, How to Get App Key?
debugheaderbooleanNoReturns test ads when debug=true, default is false

Tips

Set debug=false in the production environment.

Response Parsing

Parameter NameTypeDescription
adBlockIdstringAd spot ID
adIdstringAdvertisement ID
campaignIdstringCampaign ID
iconstringAdvertisement icon URL
imagestringAdvertisement image URL
textstringAdvertisement text
destinationobjectAdvertisement target information
destination.actionTypestringAdvertisement action type, e.g., 'visit.website'
destination.urlstringAdvertisement target URL

Complete Request Example

Execute the following request:

curl --request GET \
     --url 'https://staging.ton.ai/api/v2/openapi/matching/ad?adBlockId=66f65d8b2ec147ec042aa530&openId=16213622061&type=telegram&limit=2' \
     --header 'accept: application/json' \
     --header 'x-api-key: moJHPwHiGpSP7Lrz88xY1IAXXamF90'

A successful response will return a list of ads with a status code of 200.

{
  "data": {
    "msg": "ads success",
    "success": true,
    "ads": [
      {
        "icon": "https://file.pea.ai/ad_avatar_development/664f211f8135c60011c30dab_222777_PEPE-1.png",
        "adBlockId": "66f65d8b2ec147ec042aa530",
        "adId": "66f65baa2ec147ec042aa4a1",
        "campaignId": "66f65baa2ec147ec042aa49f",
        "image": "https://file.pea.ai/ad_development/664f211f8135c60011c30dab_801668_GoPlus.jpg",
        "text": "test ton ai",
        "destination": {
          "actionType": "visit.website",
          "url": "https://app.ton.ai"
        }
      }
    ]
  },
  "code": 0,
  "message": "success"
}

2. Report Click Event API

API Description

This API is used to report a Click event whenever a user interacts with an ad. Publishers need to call this API when a user clicks an ad.

Warning

Do not report fake Click events

Both advertiser and publisher data are reported to the Ads3 platform. Reporting false Click events will result in data discrepancies, and such behavior will lead to penalties.

Request Method

POST https://app.ton.ai/api/v2/openapi/ad/event/report

Request Parameters

Request parameters should be in JSON format, containing the following fields:

Field NameTypeRequiredDescription
eventTypestringYesEvent type, fixed value "click"
eventDataobjectYesEvent data, containing fields

The eventData object includes:

Field NameTypeRequiredDescription
adBlockIdstringYesAd spot ID, obtained from Platform -> Ad Spot -> ID
telegramUserIdstringYesUser's unique Telegram ID
adIdstringYesAd ID returned by the previous API, representing the clicked advertisement
campaignIdstringYesCampaign ID of the clicked advertisement

Complete Request Example

Execute the following request:

curl --request POST \
     --url https://staging.ton.ai/api/v2/openapi/ad/event/report \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'x-api-key: moJHPwHiGpSP7Lrz88xY1IAXXamF90' \
     --data '
{
  "eventType": "click",
  "eventData": {
    "adBlockId": "66f65d8b2ec147ec042aa530",
    "telegramUserId": "16213622061",
    "adId": "66f65baa2ec147ec042aa4a1",
    "campaignId": "66f65baa2ec147ec042aa49f"
  }
}
'

A successful response will return the ad list data, with a status code of 200.

{
  "data": {
    "status": "success",
    "msg": "report event success"
  },
  "code": 0,
  "message": "success"
}

Points to Note

  1. Only call this API when a user actually clicks on an ad.
  2. Avoid double-reporting the same click event.
  3. Retry shortly if network issues cause failure, but don’t overdo it.
  4. telegramUserId should uniquely identify the user on Telegram; do not use other identifiers.
  5. adId and campaignId should correspond to the actual clicked ad, not other ads.
Prev
User Profile