---
title: "Task Ad Integration Guide"
description: "How to integrate the AdsGram Task ad format using the adsgram-task web component: setup, customization with slots and CSS, and events."
outline: [2,3]
---

# Task Integration
## Requirements
- have [Telegram mini app](https://core.telegram.org/bots/webapps)
- know where to show ad, if not, then see [Ad integration examples](./task-examples)

## 1. Create `blockId`
Create `blockId` with Block type **`Task`**. Detailed instruction on how to get blockId you can find in [Get blockId section](./get-block-id).

::: warning
Creating more than one Block type **`Task`** is not allowed for proper functionality.
:::

![Create Task block](./images/create_task_block.webp){zoom-forbidden}

## 2. Installation
You have two options to integrate AdsGram SDK.

#### Insert script
Place the script `sad.min.js` in the `<head>` tag using this code:
```html
<script src="https://sad.adsgram.ai/js/sad.min.js"></script>
```

#### Install via npm for React and Vue.
More info about task integration from packages see in documentation for [React](https://www.npmjs.com/package/@adsgram/react#components) and [Vue](https://www.npmjs.com/package/@adsgram/vue#components).
 
::: code-group
```bash [React]
npm install @adsgram/react
```
```bash [Vue]
npm install @adsgram/vue
```
:::

## 3. Use `<adsgram-task>` web component
To integrate the task, use the `<adsgram-task>` web component.
```html
<adsgram-task
   data-block-id='your-block-id'
   data-debug="true"
   data-debug-console="false"
   class="task"
></adsgram-task>
```
You can use this web component in html, react, vue and other frameworks like native HTML element.

`your-block-id` — you get from your account on https://partner.adsgram.ai\
Detailed instruction on how to get blockId you can find in [Get blockId section](./get-block-id)

::: warning
`'your-block-id'` in task ads must be in the format `'task-xxx'`, where **xxx** are numbers.
:::

`<adsgram-task>` can accept following attributes:
* `data-block-id` — your block id from https://partner.adsgram.ai
* `data-debug` — set to true to get test task from server.
* `data-debug-console` — default is true. Works only if `data-debug` parameter is true.\
If `true` — detailed logs with `ADSGRAM DEBUG LOG` prefix will be output to the browser console. If `false` — logs are not output to the console, even in debug mode.
* `class` or `className` — set class name to styling task.

## 4. Customise task so it fits your application design
For this purpose you can use slot elements and css variables.

### Slots usage
The web component supports four slots that can be styled any way you like using classes:
- reward – displays the reward for completing the task.
- button – the button to complete the task.
- claim – displayed instead of the button after completing the task.
- done – displayed instead of the button after receiving the reward.

![Task slots](./images/task_slots.webp){zoom-forbidden}

![Task slots](./images/task_slot_claim.webp){zoom-forbidden}

![Task slots](./images/task_slot_done.webp){zoom-forbidden}

### CSS Parameters for Customization
The component supports styling via CSS variables:

```css
--adsgram-task-font-size: /* Font size of the title */
--adsgram-task-icon-size: /* Icon size */
--adsgram-task-icon-title-gap: /* Gap between the icon and the title */
--adsgram-task-icon-border-radius: /* Border radius of the icon */
--adsgram-task-button-width: /* Width of the button for completing the task */
```

Usage example:
![Css variables](./images/task_css_vars.webp)

## 5. Subscribe to events
`<adsgram-task>` has custom events, you can subscribe to this event using `addEventListener` the same way you do for basic HTML elements.
### Types of events:
 | Event              | Occurs                                                             |
 |--------------------|--------------------------------------------------------------------|
 | `reward`           | when user complete the task                                        |
 | `onError`          | when user gets an error during loading or render task              |
 | `onBannerNotFound` | when there is no task to display                                   |
 | `onTooLongSession` | when session is too long, user needs to restart the app to get ads |



## More Info
* See [code examples](./task-code-examples.md) for better understanding how to implement in your app.
* If you have troubles with integrate check [Troubleshooting section](./troubleshooting)
* If you use Typescript check [Typescript section](./typescript#task-types)
