SDK Installation
Installing the SDK is only necessary if you need to optimize conversions. If you currently lack technical development resources, you can skip this step for now; your ads can still be displayed normally.
Prerequisites
- You need to have an AppKey. If you don’t have one yet, please see Get AppKey.
SDK Initialization
Installation via npm
To install the SDK using npm, run the following command:
npm install --save ton-ai-sdk
Import via CDN
To import the SDK via CDN, add the following script tag to your HTML file:
<script src="https://cdn.jsdelivr.net/npm/ton-ai-sdk/dist/index.js"></script>
SDK Initialization
In a React Project
To initialize the SDK in a React project, import the SDK in your main file, such as App.jsx
:
import { TonAdInit } from 'ton-ai-sdk'
Then, initialize the SDK within the useEffect
hook:
useEffect(() => {
const result = TonAdInit({ appKey: 'your-app-key' })
// For staging environments, pass the staging domain like this:
// const result = TonAdInit({appKey:"your-app-key",baseUrl:'https://staging.ton.ai'});
console.log('TonAdInit', result)
}, [])
Tips
Refer to how to get an AppKey for details on obtaining your AppKey.
In Other Frameworks
For other frameworks, you can initialize the SDK once the page is fully loaded:
<script>
document.addEventListener('DOMContentLoaded', function () {
// Initialize TonAd after the DOM is ready
TonAdInit({ appKey: 'your-app-key' })
// For staging environments, use the following:
// TonAdInit({appKey:"your-app-key",baseUrl:'https://staging.ton.ai'});
})
</script>