▶ Get PSBM Labs apps on Google Play⚙ Open-source Flutter packages
FLUTTER PACKAGE · MIT LICENSE

unified_analytics_kit

A Flutter analytics toolkit that sends events to Firebase, Facebook App Events and your own backend through one API — with a persistent device ID, an offline queue and per-provider user consent.

Features

Why teams use it

One API, many destinations

logEvent reaches Firebase, Facebook and your own backend.

Consent first

Denied by default and tracked per provider.

Persistent device ID

Survives reinstall where the OS allows it.

Offline queue

Hive-backed batching, retry, backoff and Retry-After support.

Fault isolated

One failing provider never affects the others.

Validated events

Names and parameters follow Firebase and Facebook rules.

1 · Install

Add it from GitHub and pin a tag so updates never break your app.

dependencies: unified_analytics_kit: git: url: https://github.com/psbmlabs/unified_analytics_kit.git ref: v0.0.1

2 · Initialise

Call it once at startup, then log events anywhere.

await Firebase.initializeApp(); await AnalyticsManager.instance.initialize( AnalyticsConfig( enableFirebase: true, enableFacebook: true, enableDatabase: true, databaseEndpoint: Uri.parse('https://api.example.com/v1/events'), apiKey: 'your-public-app-key', ), );

3 · Log events

AnalyticsManager.instance.logEvent('app_open'); AnalyticsManager.instance.logEvent('product_viewed', parameters: {'product_id': 'p_42', 'price': 9.5}); AnalyticsManager.instance.logScreenView(screenName: 'Home');

4 · Ask for consent

if (!analytics.hasConsentDecision) { await analytics.setConsent(const AnalyticsConsent.all()); }
Routing

Choose where data goes

An event reaches a provider only when it is enabled in config, the user granted consent, and the call allows that destination. Priority: call → screen → app default.

logEvent('purchase', destinations: {AnalyticsDestination.facebook}); final screen = AnalyticsManager.instance.forScreen( 'ProductDetails', destinations: {AnalyticsDestination.database});
Backend

Simple JSON contract

The database provider POSTs batches with device_id, device info and events[] (each with a UUID id so you can ignore duplicates). 2xx removes events; 400/413/422 drops the batch; 429/5xx/timeouts retry with backoff (5 s → 5 min).

The apiKey ships inside your app, so it is not a secret. Validate payloads and rate-limit on your server.
Configuration

Key options

OptionDefaultDescription
enableFirebasetrueSend to Firebase Analytics
enableFacebooktrueSend to Facebook App Events
enableDatabasefalseSend to your backend (needs databaseEndpoint)
batchSize20Events per request (1–500)
flushInterval30 sAutomatic upload interval (min 5 s)
maxQueueSize1000Oldest events dropped beyond this
maxRetries5Failures before pausing until next launch
requestTimeout15 sPer-request timeout

Privacy & store policies

  • Declare device-ID collection in the Google Play Data safety form.
  • Publish a privacy policy covering Firebase, Facebook and your backend.
  • On iOS, show the App Tracking Transparency prompt before enabling Facebook.
  • Never pass emails or phone numbers as user IDs or parameters.

Known limitations

  • Firebase assigns its own event time; timestamp is kept only in your database.
  • Logging out offline uploads queued events later without user_id.
  • iOS cannot guarantee device-ID persistence after uninstall.

Need analytics wired into your app?

We integrate, test and ship it for you — Firebase, Facebook and custom backends.

Start a conversation