opus_tracking 0.0.9 copy "opus_tracking: ^0.0.9" to clipboard
opus_tracking: ^0.0.9 copied to clipboard

Opus Tracking is a Flutter package that provides utilities for integrating tracking and analytics features into your Flutter applications. With Opus Tracking, you can easily track user interactions, e [...]

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  late final EventClient _eventClient;

  @override
  void initState() {
    super.initState();

    // As default, 'config' param is set to default structure as OPUS currently use
    EventClient eventClient = EventTrackingFactory.create(
        tenantId: 'your-tenant-id', apiKey: 'your-api-key');
    eventClient.setSource('your-source');

    // If you want to use a custom config, please pass it as a 'config' param
    // EventClient eventClient = EventTrackingFactory.create(
    //     tenantId: 'your-tenant-id',
    //     apiKey: 'your-api-key',
    //     config: {
    //       'common_properties': {
    //         'user_id': 'user_id',
    //       },
    //       'source': 'source',
    //     });

    // Also, you can use some function that can be custom you tracking event
    // eventClient.setApiDomain('your-api-domain');
    // eventClient.setApiKey('your-api-key');
    // eventClient.setBasicInfo({
    //   'domain': 'your-domain'
    // });
    // eventClient.setIsAuthenticated(true);

    // default is Env.dev
    // eventClient.setEnv(Env.qa);

    eventClient
        .addScreenName(IScreen(uiKey: generateRandomString(10), name: 'home'));

    setState(() {
      _eventClient = eventClient;
    });
  }

  void _incrementCounter() {
    IClickParams params = IClickParams(additionalData: {});
    _eventClient.logClickEvent('increment-counter-btn', params: params);

    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            ElevatedButton(
                onPressed: () {
                  _eventClient.addScreenName(IScreen(
                      uiKey: generateRandomString(10), name: 'credential'));

                  // navigate to credential screen
                  IScreenParams params = IScreenParams(additionalData: {});
                  _eventClient.logScreenEvent('credential', params: params);
                },
                child: const Text('Go to screen credential')),
            ElevatedButton(
                onPressed: () {
                  _eventClient.removeScreenName();

                  // go back to home screen
                  IScreenParams params = IScreenParams(additionalData: {});
                  _eventClient.logScreenEvent('home', params: params);
                },
                child: const Text('Go back to screen home'))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
2
likes
0
points
3
downloads

Publisher

verified publisheropusmatch.ai

Weekly Downloads

Opus Tracking is a Flutter package that provides utilities for integrating tracking and analytics features into your Flutter applications. With Opus Tracking, you can easily track user interactions, events, and behaviors within your app to gain insights and improve user experience.

Homepage

License

unknown (license)

Dependencies

device_info_plus, fk_user_agent, flutter, flutter_native_timezone, http, logger, network_info_plus, package_info

More

Packages that depend on opus_tracking