cxorbi_flutter 0.2.0 copy "cxorbi_flutter: ^0.2.0" to clipboard
cxorbi_flutter: ^0.2.0 copied to clipboard

Cxorbi analytics for Flutter: session replay, heatmaps, screens, gestures, funnels, performance and error capture for iOS and Android.

example/lib/main.dart

import 'package:cxorbi_flutter/cxorbi_flutter.dart';
import 'package:flutter/material.dart';

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

  // 1. Start with the public source token from
  //    Capture Settings -> Data sources.
  await Cxorbi.init(CxorbiConfig(
    apiKey: const String.fromEnvironment(
      'CXORBI_SOURCE_TOKEN',
      defaultValue: 'YOUR_PUBLIC_SOURCE_TOKEN',
    ),
    environment: CxorbiEnvironment.development,
    debugMode: true,
    logLevel: LogLevel.debug,
  ));

  // 2. The SDK is opted OUT by default — nothing is captured or sent until
  //    opt-in. For production, call this from your consent dialog instead.
  await Cxorbi.instance.optIn();

  // 3. Deterministic verification event: confirm this in Live Events.
  Cxorbi.instance.track('cxorbi_integration_test', {
    'source': 'example_app',
  });

  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cxorbi Flutter Example',
      // 4. Automatic screen tracking for every named route.
      navigatorObservers: [CxorbiNavigatorObserver()],
      initialRoute: '/home',
      routes: {
        '/home': (_) => const HomeScreen(),
        '/details': (_) => const DetailsScreen(),
      },
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                // Attach your user id after login.
                Cxorbi.instance.identify('user-123', {'plan': 'premium'});
                // Track a custom event (feeds funnels and journeys).
                Cxorbi.instance.track('cta_tapped', {'screen': 'home'});
                Navigator.of(context).pushNamed('/details');
              },
              child: const Text('Go to details'),
            ),
            const SizedBox(height: 12),
            ElevatedButton(
              onPressed: () {
                // Manual screen call example for tabs/PageViews/custom routers.
                Cxorbi.instance.screen('/home-manual-example');
              },
              child: const Text('Track manual screen'),
            ),
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('Tap, scroll, and navigate to generate data.'),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: () {
                // Send transactions exactly once from the purchase success
                // callback, not from a screen build/initState.
                Cxorbi.instance.trackTransaction(
                  orderId: 'example-order-001',
                  revenue: 4999,
                  currency: 'USD',
                  items: const [
                    {'sku': 'demo-plan', 'qty': 1, 'price': 4999},
                  ],
                );
              },
              child: const Text('Track demo purchase'),
            ),
            const SizedBox(height: 12),
            ElevatedButton(
              onPressed: () {
                // On logout: clear identity + user/event properties and rotate
                // to a fresh session so the next user is never mixed in.
                Cxorbi.instance.reset();
                Navigator.of(context).popUntil((r) => r.isFirst);
              },
              child: const Text('Log out'),
            ),
          ],
        ),
      ),
    );
  }
}
32
likes
0
points
1.13k
downloads

Publisher

unverified uploader

Weekly Downloads

Cxorbi analytics for Flutter: session replay, heatmaps, screens, gestures, funnels, performance and error capture for iOS and Android.

Homepage

Topics

#analytics #session-replay #heatmaps #monitoring

License

unknown (license)

Dependencies

crypto, cryptography, ffi, flutter, flutter_secure_storage, http, path_provider

More

Packages that depend on cxorbi_flutter

Packages that implement cxorbi_flutter