Flutter

Modified on Wed, 13 Nov at 1:31 PM

The CUX Analytics SDK integrates with Flutter (Android and iOs) applications to automatically detect user activities. With the addition of a few lines of code you can monitor and analyze your entire application to understand how the user uses it. The result of such monitoring is presented on CUX Analytics Dashboard.


Supported platforms / frameworks

The CUX Analytics SDK now is based on Flutter SDK 3.22.2 and has back compatibility with higher versions.


How to start

  1. Instal CUX SDK from pub dev: https://pub.dev/packages/cux_analytics_sdk
  2. For Android check internet permission:
    <uses-permission android:name="android.permission.INTERNET" />
  3. In main() function of your Flutter app wrap with AnalyticsWidget your root widget. Before wrapping execute init function using your CUX token. For better observability add NavigationObserver in your MaterialApp:
    void main() {
      print("CuxSDK: main()");
      runApp(const MyApp());
    }
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
      @override
      Widget build(BuildContext context) {
        CuxAnalytics.init(context, 'token');
        return AnalyticsWidget(
          child: MaterialApp(
            title: 'Flutter CUX Demo',
           ...
            home: const HomeWidget(),
            navigatorObservers: [
              CuxAnalytics.createNavigationObserver(context, this)
            ],
          ),
        );
      }
    }
        
  4. If you use go_router add RouterNavigationListener:
    @override
      Widget build(BuildContext context) {
        return MaterialApp.router(
          routerConfig: _router,
          debugShowCheckedModeBanner: false,
          onNavigationNotification:
              RouterNavigationListener(rootWidget: this).onNavigationNotification,
        );
      }
    }
      
  5. If pages in your app are not MaterialApp or Scaffolds then for better navigation observability wrap widgets of your screens in DestinationWidget with unik destination name:
    @override
      Widget build(BuildContext context) {
        return DestinationWidget(
          destinationName: "Destination_$name",
          child: Column(...
      


Screenshots

CUX Analytics SDK is able to make screenshots of a user’s session and provide you access to them on Dashboard.

To provide full security of user’s data SDK don’t save and don’t send anywhere data of such input fields as EditText.

You can manage the network and CPU consumption by adjusting screenshots via changing scale of screenshots compression depending on the type of internet connection.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article