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
})

The Promise resolves only when the SDK receives confirmation from the backend that the ad event (such as an impression) was registered and processed.

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 using increasing intervals:
    • 1.5 seconds
    • 3 seconds
    • 4.5 seconds
  • If a successful response is received during this polling — the .then() callback resolves.
  • If no valid response is received after all attempts — the .catch() callback fires.

This makes frontend callbacks reliable, but not instant.

What You Get in the Callback #

When the Promise resolves, it includes the same enriched event data as server-side postbacks:

FieldDescription
event_typeimpression or click
ymidYour original event/session identifier
reward_event_typevalued or not_valued
estimated_priceApproximate payout (USD)
zone_idMain zone ID
sub_zone_idActual zone ID where the event occurred
request_varPlacement ID (e.g. button, screen name)
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("Ad was shown but not monetized.")
  }
}).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 messageOptional
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.