Frontend Callback

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 show and 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:

FieldDescription
event_typeimpression or click
variable2Your ymid (the result has no ymid key)
reward_event_typevalued or non_valued
estimated_priceEstimated earnings (USD). Absent when the event is non_valued
zone_idMain zone ID
sub_zone_idActual zone ID where the event occurred
request_varPlacement ID (e.g. button, screen name). Rewarded Popup: <main zone ID>_<requestVar>
telegram_idTelegram 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 CaseFrontend CallbackServer-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.