Web (JS/TS)

Version 1.3.11

Add Taddy script to <head>...</head> section after telegram sdk script

<script src="https://sdk.taddy.pro/web/taddy.min.js?1311" data-pub-id="XXX"></script>

Replace XXX with your Public ID

After the script is loaded, the init() method will be called automatically and the ready event will be emitted. Taddy object can be accessed via window.Taddy

Advanced integration

  1. Add Taddy script to <head>...</head> section after telegram sdk script

<script src="https://sdk.taddy.pro/web/taddy.min.js?1311"></script>
  1. Install TypeScript declarations (optional). This package includes only types declarations without implementation. Adding the Taddy script to the head section is required (see Step 1).

npm i taddy-sdk-web@1.3.11
  1. Initialize Taddy

const taddy = window.Taddy;

taddy.init('xxxxxxxxxxx-pub-id-xxxxxxxxxxx');
  1. Send "ready" event when app is loaded

taddy.ready()

Exchange

  1. Get exchange service

const exchange = taddy.exchange();
  1. Fetch exchange feed

exchange.feed({
    limit: 8,              // default: 4
    imageFormat: 'png',    // default: webp
    autoImpressions: true, // impressions event will be called
    showCompleted: true    // default: false
}).then((items) => {
    // render(items)
});
  1. Send impressions (manual)

exchange.impressions(items);
  1. Open item via Telegram (item click handler)

// open task with auto check
exchange.open(item).then(() => {
    // exchange completed! 
    // reward user, remove task from list, etc...
}).catch(() => {
    // exchange is not completed! 
});

// or open task with manual check
exchange.open(item, false);
// manual check
exchange.check(item).then(success => {
    // if success=true - exchange completed! 
    // reward user, remove task from list, etc...
});
  1. Send custom event ...

Ads

  1. Получаем рекламный сервис Taddy

const ads = taddy.ads();

// или можем обращаться напрямую без создания переменной
taddy.ads()
  1. Выполняем загрузку и показ рекламного объявления interstitial

ads.interstitial({
    // можем добавить обработчик закрытия объявления
    onClosed: () => console.log('Объявление закрыто'),
    onViewThrough: (id: string | null) => console.log('Объявление просмотрено', id);
}).then((success: boolean) => {
    // success содержит признак того, что объявление было показано
});

// Минимальный код
ads.interstitial();
// или
taddy.ads().interstitial();

Last updated