AdFrequencyCap class
Enforces per-session and per-day frequency caps on ad impressions.
Prevents over-saturating users with ads in a single session or day.
final cap = AdFrequencyCap(maxPerSession: 5, maxPerDay: 20);
await cap.load();
if (cap.canShow) {
await AdManager.instance.showInterstitial();
cap.recordImpression();
}
Constructors
- AdFrequencyCap({int maxPerSession = 5, int maxPerDay = 20})
- Creates a frequency cap.
Properties
- canShow → bool
-
Whether another ad can be shown given current caps.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessionImpressions → int
-
Number of ads shown in the current session.
no setter
- todayImpressions → int
-
Number of ads shown today (calendar day).
no setter
Methods
-
load(
) → Future< void> -
Loads today's impression count from
SharedPreferences. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordImpression(
) → Future< void> - Records one ad impression, incrementing both session and day counters.
-
resetForTesting(
) → Future< void> - Resets all counters and persisted state.
-
resetSession(
) → void - Resets only the session counter (e.g. when the app moves to background and returns after a significant gap).
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited