magnitude 1.0.0 copy "magnitude: ^1.0.0" to clipboard
magnitude: ^1.0.0 copied to clipboard

Flutter SDK for Magnitude analytics — event tracking, session management, autocapture, and offline support.

Magnitude Flutter SDK #

Flutter SDK for Magnitude analytics. Track events, identify users, manage sessions, and autocapture screen views.

Installation #

dependencies:
  magnitude: ^1.0.0

Quick Start #

import 'package:magnitude/magnitude.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Magnitude.init('YOUR_API_KEY', config: MagnitudeConfig(
    apiUrl: 'https://your-ingest-url.com/ingest-events',
    autocapture: true,
  ));

  runApp(MyApp());
}

Usage #

Track Events #

Magnitude.track('button_clicked', properties: {
  'button_name': 'checkout',
  'page': 'cart',
});

Identify Users #

Magnitude.identify('user_123', traits: {
  'email': 'jane@example.com',
  'plan': 'pro',
});

Super Properties #

Register properties that are included in every event:

Magnitude.register({'app_version': '2.1.0', 'platform': 'ios'});

Reset #

Clear the identified user and revert to anonymous (device ID):

Magnitude.reset();

Opt Out / In #

Magnitude.optOut();  // track() becomes a no-op
Magnitude.optIn();   // resume tracking

Autocapture Screen Views #

Add the navigator observer to your MaterialApp:

MaterialApp(
  navigatorObservers: [Magnitude.navigatorObserver],
  // ...
);

This automatically tracks [Auto] Screen View events with $screen_name for every named route push/pop.

Configuration #

Parameter Default Description
apiUrl Magnitude ingest URL Event ingest endpoint
autocapture false Auto-track screen views
flushIntervalMs 5000 Queue flush interval (ms)
maxBatchSize 200 Max events per batch
sessionTimeoutMs 1800000 Session timeout (30 min)
maxRetries 3 Retry attempts for failed requests

How It Works #

  • Sessions: A new session starts when 30 minutes of inactivity have passed. A $session_start event fires automatically.
  • Batching: Events queue locally and flush every 5 seconds or when the batch hits 200 events.
  • Offline: The queue persists to shared_preferences, so events survive app restarts.
  • Retry: Failed requests retry 3 times with 1s/2s/4s exponential backoff. 400 responses drop the batch.
  • Lifecycle: The queue flushes on AppLifecycleState.paused and checks for session timeout on resumed.
0
likes
160
points
10
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter SDK for Magnitude analytics — event tracking, session management, autocapture, and offline support.

Repository (GitHub)
View/report issues

Topics

#analytics #tracking #events #sessions

License

MIT (license)

Dependencies

flutter, http, shared_preferences, uuid

More

Packages that depend on magnitude