Frontend Callback #
The Monetag SDK provides a built-in frontend callback mechanism based on backend-confirmed events.
It allows your app to respond to confirmed ad interactions directly in the user interface β such as unlocking content, displaying messages, or triggering rewards.
This callback is implemented via a Promise returned by the SDK function show_XXX().
How It Works #
When an ad is triggered using the SDK:
show_XXX().then((result) => {
// Frontend Callback: ad event confirmed by backend
}).catch(() => {
// Ad failed, rejected, or timed out
})
On zones with reward postback (enabled by default), the Promise of Rewarded Interstitial and Rewarded Popup resolves with the event data once Monetag confirms the event: for Rewarded Interstitial after the ad is closed, for Rewarded Popup from about 2 seconds after the tab opens. In other cases it resolves with no value, so check the result before you read its fields.
Under the hood: #
- After showing the ad, the SDK sends a request to the backend.
- Then it polls for the event confirmation up to 3 times, pausing 1.5, 3 and 4.5 seconds after each empty answer (about 9 seconds in total).
- If a successful response is received during this polling, the
.then()callback resolves. - If the event is still unknown after all attempts, the Promise rejects with
Failed to verify the ad showand the.catch()callback fires.
This makes frontend callbacks reliable, but not instant.
What You Get in the Callback #
When the Promise resolves, it includes a subset of the postback fields:
| Field | Description |
|---|---|
event_type | impression or click |
variable2 | Your ymid (the result has no ymid key) |
reward_event_type | valued or non_valued |
estimated_price | Estimated earnings (USD). Absent when the event is non_valued |
zone_id | Main zone ID |
sub_zone_id | Actual zone ID where the event occurred |
request_var | Placement ID (e.g. button, screen name). Rewarded Popup: <main zone ID>_<requestVar> |
telegram_id | Telegram User ID (if passed by Telegram SDK) |
π See the Macro Reference section for a full description for each field.
Example usage:
show_XXX().then((event) => {
if (event?.reward_event_type === "valued") {
giveReward()
} else {
showInfo("No reward for this ad.")
}
}).catch(() => {
showError("Ad did not complete.")
})
Limitations #
- Relies on client-server communication: may fail if the user’s connection is unstable.
- Only works for Rewarded Interstitial and Rewarded Popup.
- Does not work for In-App Interstitial.
- If the user closes the app too early, the
.then()may never resolve.
Best Practices #
- β Use frontend callbacks for user experience and optimistic UI flows
- β Combine with postbacks for accounting and reward logic
- β
Always handle
.catch()to detect timeouts or failed loads - β Donβt rely solely on
.then()to issue real-world rewards
Summary #
| Use Case | Frontend Callback | Server-Side Postback |
|---|---|---|
| Show UI message | β | Optional |
| Grant in-app currency | β οΈ Still use postback | β |
| Trigger animation | β | β |
| Confirm event value | β οΈ Partial | β |
| Track monetization | β | β |
Frontend callbacks now reflect real backend-confirmed events, offering both flexibility and transparency β while server-side postbacks remain the foundation for critical reward and revenue logic.