> For the complete documentation index, see [llms.txt](https://tappadsdocs.gitbook.io/tappads/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tappadsdocs.gitbook.io/tappads/publishers/feed-integration/sdk-integration-guide.md).

# SDK integration guide

### **Step 1: SDK Integration**

To enable SDK functionality on your TMA, add the following code to the `<head>` section of your page:

```jsx
<script src="https://sdk.tappads.io/pub/sdk_v1.js"></script>
```

This code loads the SDK for integrating advertising functionality.

### **Step 2: SDK Initialization**

After adding the SDK, initialize it to specify who is using it and how it should operate.

```jsx
TappAdsPubSdk.init('adv_apikey', {
  debug: true
})
  .then(() => {
    console.log('TappAdsPubSdk initialized');
  })
  .catch(err => {
    console.error('TappAdsPubSdk initialization error:', err);
  });
```

This code initializes the TappAds SDK with the provided API key and enables debug mode. After successful initialization, a message is displayed in the console. If there's an error, it will be logged as well.

**Parameters:**

* `adv_apikey`: Your API key for SDK usage.
* `debug: true`: Debug mode. Set to false in production to disable debug messages.

### **Step 3: Fetching the Feed**

After initialization, retrieve the feed—a list of tasks available for users on your page.

```jsx
TappAdsPubSdk.getFeed()
  .then(feed => {
    console.log('Feed:', feed);
  })
  .catch(err => {
    console.error('Feed error:', err);
  });
```

This code uses the `getFeed()` method from the TappAds SDK to obtain the task feed. It returns a Promise handled by `.then()` and `.catch()`:

* If successful, the feed is displayed in the console.
* If an error occurs, it’s logged in the console with "Feed error."

This code is part of the SDK integration process and follows the SDK initialization steps.

**Example Feed:**

The feed is an array of objects, where each object represents a task.

```jsx
const feed = [
  {
    btn_label: "Get reward",
    name: "Subscribe to channel",
    description: "Channel about games",
    icon: "https://site.domain/icon.jpg",
    id: 1,
    is_done: false,
    payout: 0.01
    completed_elsewhere: false
  }
];
```

**Object Fields:**

* `btn_label`: Button text.
* `name`: Task name.
* `description`: Task description.
* `icon`: Task icon.
* `id`: Unique task identifier.
* `is_done`: Completion flag.
* `payout`: Reward amount.
* `completed_elsewhere`: If the user has completed the task elsewhere, the field will be true and you will be able to issue the reward<br>

### **Step 4: Starting a Task**

To start a task, use `taskStart` with the task ID.

```jsx
TappAdsPubSdk.taskStart(taskId)
  .then(() => {
    console.log('Task started:', taskId);
  })
  .catch(err => {
    console.error('Task start error:', err);
  });
```

This code calls the `taskStart` method in the TappAds SDK, passing `taskId` (task identifier). It returns a Promise handled as follows:

* If the task starts successfully, "Task started" with the task ID is logged.
* If an error occurs, it’s logged with "Task start error."

Replace `taskId` with a real task ID from your feed.

* `taskId`: ID from the feed.

### **Step 5: Checking Task Statuses**

To check the status of tasks, use `getTaskStatus` with an array of task IDs.

```jsx
TappAdsPubSdk.getTaskStatus(taskIds)
  .then(res => {
    console.log('statuses:', res);
  })
  .catch(err => {
    console.error('Error get statuses:', err);
  });
```

This code uses the `getTaskStatus` method from the TappAds SDK to check task statuses. It accepts an array of `taskIds` (task identifiers) and returns a Promise. The result is handled as follows:

* If the statuses are successfully retrieved, they’re logged in the console.
* If there’s an error, it’s logged as "Error get statuses."

Replace `taskIds` with an actual array of task IDs whose statuses you want to check.

**Sample Status Response:**

```jsx
{
  "1": "new"
}
```

**Possible Statuses:**

* `new`: Task created.
* `started`: Task started by the user.
* `completed`: Task completed.

These steps will help you integrate and use the TappAds SDK effectively.
