Flutter remote config and analytics
Per-user remote config with ETag revalidation and exposure tracking; the consent-gated, allowlisted analytics event queue.
On this page
Concepts: Events, Consent and privacy. Endpoints: Engagement API, Analytics API.
Remote config
core.remoteConfig (RemoteConfigClient) reads GET /v1/engagement/config/client. Status: fixture-tested.
final rc = core.remoteConfig;
final cfg = await rc.fetch(); // RemoteConfig
final variant = cfg.get<String>('paywall_variant');
// When the user actually reaches the feature, read it with expose() instead:
final shown = rc.expose<bool>('show_streaks'); // records one exposure per key per config version- Signed-in only. With no session,
fetch()returns the cached or empty config and sends no request. - Caching. The SDK sends
If-None-Matchwith the lastETag. A304keeps the current values. It honoursCache-Control: max-age(clamped to 0–3600 s; 60 s when absent) and does not ask again before then unless you passfetch(force: true). - Last known good. If the server is unreachable or returns an error or a malformed body,
fetch()returns the last good values. They come from memory, or from secure storage after a restart.cfg.fromCachetells you which.fetch()does not throw anAppCoreProblem. - Per user. The cache is bound to the user. An account switch never inherits the previous user's assignment.
- Exposure.
expose()emitsproduct.config_exposed.v1(flag_key,variant,config_version) through analytics once per key and config version. That event is subject to analytics consent like any other. rc.currentis the latest value without a request.RemoteConfig.empty()has version"0".
Remote config values are rollout and presentation hints. Never use them to grant access. Paid access comes only from entitlements. Never take prices from them either; prices come from the store.
Analytics
core.analytics (Analytics) is a bounded, consent-gated queue that posts to POST /v1/analytics/events. Status:
fixture-tested.
final analytics = core.analytics;
// Consent is OFF by default and held in memory only. Set it on every launch from the user's saved choice.
analytics.consentGranted = userAllowedAnalytics;
final recorded = await analytics.track('product.lesson_completed.v1', {
'lesson_ref': 'lesson_42',
'duration_s': 310,
});
// recorded == false: no consent, or nobody is signed in
await analytics.flush(); // e.g. when the app is paused; returns how many events the server acceptedAllowed event names and properties
Clients may send only these registered event types (ClientEvent.schema.json), each with only the listed property
keys. clientEventAllowlist in the SDK holds the same table.
event_type | Allowed properties |
|---|---|
product.app_opened.v1 | cold_start |
product.screen_viewed.v1 | screen |
product.lesson_started.v1 | lesson_ref |
product.lesson_completed.v1 | lesson_ref, duration_s |
product.question_answered.v1 | question_ref, correct |
product.paywall_viewed.v1 | placement, catalog_product_id |
product.purchase_ui_cancelled.v1 | catalog_product_id (sent by the SDK on store cancel) |
product.notification_opened.v1 | notification_ref, action |
product.config_exposed.v1 | flag_key, variant, config_version (sent by the SDK from remoteConfig.expose) |
Values must be null, bool, num, or a String of at most 128 characters. track throws ArgumentError, not
an AppCoreProblem, for an unregistered type, a property not on the list, or a value of the wrong type. That is a
programming error, so fix it during development. Never put personal data (names, emails, free text) in properties.
Server-side domain events (purchases, entitlement changes, sign-ups) are produced by the backend. The client never sends them.
Queue behaviour
| Behaviour | Detail |
|---|---|
| Consent gate | track records nothing while consentGranted is false. revokeConsent() sets it to false and clears unsent events. |
| Owner binding | Each event is tagged with the user who was signed in when it was captured. On sign-out or account switch, other users' events are dropped and never relabelled. Nothing is recorded while signed out. |
| Capacity | 500 events in memory. When full, low-priority events are dropped first; paywall_viewed, purchase_ui_cancelled and lesson_completed are kept. analytics.dropped counts the losses. |
| Flushing | Automatic once 20 events are queued. core.logout() also flushes. Otherwise call flush() yourself, for example on AppLifecycleState.paused. flushDelay(failures) gives a jittered backoff (up to about 5 minutes) for a periodic flush. |
| Batching and retries | Up to 100 events per batch. Each event has a stable event_id, and the batch Idempotency-Key is derived from those ids, so a retry is not counted twice. Retryable failures are retried by the transport. If the retries run out, flush() throws the AppCoreProblem and the events stay queued. A 400 or 422 batch is dropped, not retried forever. |
| Persistence | In memory only. Queued events are lost if the process is killed. This is deliberate: nothing unencrypted is written to disk. |
The SDK does not link consentGranted to the server's consent record. When the user changes the setting, record it
with privacy.setConsent('optional_analytics', ...) and set consentGranted (or call revokeConsent()). See
Privacy. The reference app's settings screen does both.
Warning
Not yet enabled: restoring analytics consent from the server. There is no consent read endpoint in the
contract, and the SDK keeps consentGranted in memory. Save the user's choice yourself and set it after every
AppCore.init.