Skip to main content

openpanel_dart_flutter 0.1.4 copy "openpanel_dart_flutter: ^0.1.4" to clipboard
openpanel_dart_flutter: ^0.1.4 copied to clipboard

Flutter integration for openpanel_dart: screen tracking, referrer and lifecycle observers, plus shared_preferences and device_info backed storage/metadata.

openpanel_dart_flutter #

Flutter integration for OpenPanel. Use this package in Flutter apps.

For plain Dart, CLI, server, web, use the core package openpanel_dart instead (see its README).

This package re-exports the whole openpanel_dart API and adds the Flutter specific pieces on top of it, so a Flutter app only needs a single import:

  • OpenpanelRouteObserver -> automatic screen_view tracking for named routes.
  • OpenpanelReferrerObserver -> install/deeplink referrer on Android & iOS.
  • OpenpanelLifecycleObserver -> flush the queue when the app is backgrounded.
  • SharedPreferencesStore -> shared_preferences backed KeyValueStore.
  • FlutterDeviceContext -> app/device metadata from device_info_plus and package_info_plus.
  • initOpenpanelFlutter -> one call that wires the two above.

Getting started #

import 'package:openpanel_dart_flutter/openpanel_dart_flutter.dart';

final analytics = OpenpanelAnalytics.instance;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  WidgetsBinding.instance
    ..addObserver(OpenpanelReferrerObserver(analytics: analytics))
    ..addObserver(OpenpanelLifecycleObserver(analytics: analytics));

  await initOpenpanelFlutter(
    analytics,
    config: const OpenpanelConfig(
      clientId: 'YOUR_CLIENT_ID',
      // Self-hosting? Point apiUrl at your own instance:
      // apiUrl: 'https://analytics.example.com',
    ),
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // Tracks every route change as a `screen_view` event.
      navigatorObservers: [OpenpanelRouteObserver()],
      home: const HomeScreen(),
    );
  }
}

Manual storage / metadata #

If you do not want initOpenpanelFlutter, pass the Flutter implementations yourself:

final prefs = await SharedPreferences.getInstance();

await analytics.init(
  config: const OpenpanelConfig(clientId: 'YOUR_CLIENT_ID'),
  keyValueStore: SharedPreferencesStore(prefs),
  deviceContext: FlutterDeviceContext(),
);

Origin header: browsers control the Origin header, so on the web configure CORS on the server instead of passing it through OpenpanelConfig.

Running the example #

cd example
flutter pub get
flutter run

Set a real clientId (and apiUrl for a self-hosted instance) in example/lib/main.dart to deliver events.

License #

MIT, see LICENSE. The core package and third-party dependencies are distributed under their own licenses.

0
likes
160
points
122
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter integration for openpanel_dart: screen tracking, referrer and lifecycle observers, plus shared_preferences and device_info backed storage/metadata.

Repository (GitHub)
View/report issues

Topics

#analytics #openpanel #flutter

License

MIT (license)

Dependencies

device_info_plus, flutter, openpanel_dart, package_info_plus, referrer, shared_preferences

More

Packages that depend on openpanel_dart_flutter