💥If you want to make a multistep task for more user engagement, this 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.
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.
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.
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
<!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.