InterstitialPlacementPolicy

Overview

Android-only gate that decides when to show an interstitial based on your navigation route grammar and a few safety rules (cooldown, grace period, session cap). It raises a VoidEvent so your ad loader (e.g., AdMobBootstrap) actually displays the ad.

Platform

  • Android only (#if UNITY_ANDROID).

Atoms / Inputs

  • StringVariable navigationRoute — bind to your current route (e.g., "", sec/{id}, sec/{id}/sub/{id}, sec/{id}/sub/{id}/q/{id}).
  • BoolReference interstitialReady — set by your ad loader when an interstitial is preloaded.
  • VoidEvent adsShowInterstitial — raised to request showing an interstitial.

Rules

  • cooldownSeconds (default 120s): minimum time between interstitials.
  • postLaunchGraceSeconds (default 30s): minimum time after app start before any interstitial.
  • sessionCap (default 3): maximum interstitials per session (0 = unlimited; not recommended).

Route Transitions Considered “Natural Breaks”

  • Question → Subsection (closing a question)
  • Subsection → Section (closing a subsection)
  • Section → Root (leaving a section)

Behavior

  • Tracks the previous and new route; on a natural break, if the rules pass and interstitialReady is true, it raises adsShowInterstitial and advances the internal counters.
  • Skips entirely when PlayerPrefs["paidVersion"] == 1 (Remove Ads purchased).

Integration Notes

  • Wire this to the same Unity Atoms used by your ad loader.
  • Keep the navigation string in sync with your router so breaks are detected reliably.