> 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/advertisers/instructions-for-integration/sdk-integration-instructions.md).

# SDK Integration Instructions

💥If you want to make a multistep task for more user engagement, this [integration](/tappads/advertisers/instructions-for-integration/sdk-integration-instructions-multi-step-tasks.md) will work for you

## Step 1. Connect the SDK

In the `head` section of your Telegram Mini App page, you need to add the SDK script. This will allow you to track events, send data on target actions, and receive analytics.

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

## Step 2. Initialize the SDK

After connecting the script, you need to initialize the SDK with your API key (`adv_apikey`). This key has been provided to you to interact with our platform.

```jsx
TappAdsAdvSdk.init('your_adv_apikey', {
    debug: true, // Leave as true for debugging
})
.then(() => {
    console.log('TappAdsAdvSdk initialized');
})
.catch(err => {
    console.error('Error initializing TappAdsAdvSdk:', err);
});
```

> **Important:** Make sure to use the correct API key. If the initialization is successful, you’ll see a success message in the console.

## Step 3. Configure the Target Action

To track a target action (e.g., opening the TMA or performing an in-app action), use the `TappAdsAdvSdk.event` method. This will send an event when the user performs the specified target action.

```jsx
TappAdsAdvSdk.event({
    isOld: false // Set to true if the user has already been in the app before
})
.then(() => {
    console.log('Event successfully sent');
})
.catch(err => {
    console.error('Error sending event:', err);
});
```

* Parameter `isOld`:
  * `false` — if this is a new user.
  * `true` — if the user has previously been in the app and is performing the action again.

> **Note:** Configuring this parameter is important for identifying unique users and accurately calculating payments for new users.

## Example of Full Integration Code

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Your Telegram Mini App</title>
    <!-- Connect the SDK script -->
    <script src="https://sdk.tappads.io/adv/sdk_v1.js"></script>
</head>
<body>
    <script>
        // Check if TappAdsAdvSdk object exists
        if (typeof TappAdsAdvSdk === 'undefined') {
            console.error('TappAdsAdvSdk is not loaded. Please check the SDK connection.');
        } else {
            // Initialize the SDK
            TappAdsAdvSdk.init('your_adv_apikey', { debug: true })
            .then(() => {
                console.log('TappAdsAdvSdk initialized successfully');
                // Send the target event after successful initialization
                trackEvent();
            })
            .catch(err => {
                console.error('Error initializing TappAdsAdvSdk:', err);
            });

            // Function to send the target event
            function trackEvent() {
                TappAdsAdvSdk.event({ isOld: false })
                .then(() => {
                    console.log('Event sent successfully');
                })
                .catch(err => {
                    console.error('Error sending event:', err);
                });
            }
        }
    </script>
</body>
</html>
```

### Conclusion

* Check for the presence of `TappAdsAdvSdk` before initialization.
* Use the `TappAdsAdvSdk.event()` function to log the target action.

If you have any questions, please contact our support team.
