opus_tracking 0.1.5
opus_tracking: ^0.1.5 copied to clipboard
Opus Tracking - Effortlessly integrate tracking & analytics into your Flutter apps. Gain insights, monitor user interactions, & optimize user experience.
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',
source: 'your-application-source',
apiDomain: 'your-api-domain');
// 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);
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')),
ElevatedButton(
onPressed: () {
dynamic params = {};
_eventClient.logBehaviourEvent('increment-counter-event',
params: params);
},
child: const Text('Log behavior event'))
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}