What is storage?
Storage is the persistence layer for tracking presentation events. It records:- Impressions - When presentations are shown
- Dismissals - When users close presentations
- Conversions - When users take action
Storage interface
ImplementPresentumStorage<S, V>:
SharedPreferences implementation
Generic production implementation using SharedPreferences, that can be used for any presentum:Per-surface-variant tracking lets the same campaign appear differently on
different surfaces with independent impression counts.
In-memory implementation
For testing or session-only tracking, use built-in InMemoryPresentumStorageBackend API implementation
Sync events to a backend:No-op storage (default)
If you don’t provide a storage implementation, Presentum usesNoOpPresentumStorage:
NoOpPresentumStorage does nothing and returns default values:
getLastShown()→nullgetShownCount()→0getDismissedAt()→null- All
record*()methods → no-op with warning log
Storage event handler
UsePresentumStorageEventHandler to automatically record events:
Best practices
Always provide storage in production
Always provide storage in production
Don’t rely on
NoOpPresentumStorage. Always pass a real storage implementation:Handle period-based counts
Handle period-based counts
getShownCount receives a period parameter. Only count impressions within
that timeframe: dart final cutoff = DateTime.now().subtract(period); final recentCount = timestamps.where((t) => t.isAfter(cutoff)).length; Initialize storage synchronously
Initialize storage synchronously
Avoid async initialization in
initState. Use SharedPreferencesWithCache for synchronous access:Enable logs during development
Enable logs during development
Use This helps catch missing storage implementations during development.
--dart-define=presentum.logs=true to see NoOpPresentumStorage warnings and other logs: