analytics_exa_flutter 1.1.0
analytics_exa_flutter: ^1.1.0 copied to clipboard
Package de analytics.
example/lib/main.dart
import 'package:analytics_exa_flutter/analytics_exa_flutter.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
GlobalKey<NavigatorState> navigatorKey = GlobalKey();
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final ExaAnalytics _exaAnalytics;
@override
void initState() {
super.initState();
getData();
}
Future getData() async {
String firebaseToken = await FirebaseMessaging.instance.getToken() ?? '';
final inngageProps = InngageProps(
appToken: '598296a47378a4f2304c6ce6b7e7d32c',
firebaseToken: firebaseToken,
identifier: 'example@exa.com.br',
navigatorKey: navigatorKey,
requestAdvertiserId: true,
blockDeepLink: true,
);
_exaAnalytics = ExaAnalytics();
_exaAnalytics.init(
inngageProps: inngageProps,
appFlyerProps: null,
);
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
navigatorKey: navigatorKey,
title: 'Analytics Exa Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text("Analytics Exa Example"),
),
body: Center(
child: ListView(
children: [
_elevatedButtonCustom(
onPressed: () {
_exaAnalytics.setCurrentScreen(screenName: "screenName");
},
child: const Text("setCurrentScreen"),
),
_elevatedButtonCustom(
onPressed: () {
_exaAnalytics.setLogEvent(
eventName: 'setLogEvent',
params: {
'param1': 'param1',
'param2': 'param2',
},
);
},
child: const Text("setLogEvent"),
),
_elevatedButtonCustom(
onPressed: () {
_exaAnalytics.setLogUserId(
id: 'setLogUserId',
);
},
child: const Text("setLogUserId"),
),
_elevatedButtonCustom(
onPressed: () {
_exaAnalytics.setLogUserProperties(
name: 'setLogUserProperties',
value: 'userId',
customFields: {
'param1': 'param1',
'param2': 'param2',
},
listUseOnly: [
UseAnalyticsOnly.Firebase,
UseAnalyticsOnly.Inngage,
],
);
},
child: const Text("setLogUserProperties"),
),
],
),
),
),
);
}
void showSnackBar({
required BuildContext context,
required String message,
Duration? duration,
}) {
print(message);
ScaffoldMessenger.of(context)
.clearSnackBars(); //clear any snack bars in queue and show current one
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.blue,
duration: duration ?? const Duration(seconds: 3),
content: Text(
message,
style: const TextStyle(
fontSize: 16,
color: Colors.white,
),
),
),
);
}
}
Widget _elevatedButtonCustom({
required Function() onPressed,
required Widget child,
}) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: onPressed,
child: child,
),
);
}