-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_analytics.sh
87 lines (79 loc) · 2.32 KB
/
create_analytics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
mkdir "lib/src/app/analytics"
mkdir "lib/src/app/analytics/base"
mkdir "lib/src/app/analytics/analytics_tools"
mkdir "lib/src/app/analytics/utilities"
touch "lib/src/base/base_analytics_tool.dart"
touch "lib/src/app/analytics/analytics_tools/tool.dart"
touch "lib/src/app/analytics/analytics_service.dart"
touch "lib/src/app/analytics/utilities/event_names.dart"
touch "lib/src/app/analytics/utilities/page_names.dart"
# write Analytics service
cat <<EOF > "lib/src/app/analytics/analytics_service.dart"
import 'package:get/get.dart';
import 'package:getx_template/src/app/analytics/analytics_tools/tool.dart';
import 'package:getx_template/src/base/base_analytics_tool.dart';
class AnalyticsManager extends GetxService {
final List<BaseAnalyticsTool> _availableTools = [
AnalyticsTool(),
];
@override
void onReady() {
super.onReady();
_setupTools();
}
Future<void> _setupTools() async {
for (BaseAnalyticsTool tool in _availableTools) {
await tool.setupTool();
}
}
Future<void> logEvent({
required String eventName,
Map? eventParams,
}) async {
for (BaseAnalyticsTool tool in _availableTools) {
await tool.logEvent(
eventName: eventName,
eventParams: eventParams,
);
}
}
}
EOF
# Write analytics tool template
cat <<EOF > "lib/src/base/base_analytics_tool.dart"
abstract class BaseAnalyticsTool {
Future<void> setupTool();
Future<void> logEvent({
required String eventName,
Map? eventParams,
});
}
EOF
# write an example analytics tool
cat <<EOF > "lib/src/app/analytics/analytics_tools/tool.dart"
import 'package:getx_template/src/base/base_analytics_tool.dart';
class AnalyticsTool extends BaseAnalyticsTool {
final _toolExcludedEvents = <String>[];
@override
Future<void> setupTool() async {}
@override
Future<void> logEvent({required String eventName, Map? eventParams}) async {
if (_toolExcludedEvents.contains(eventName)) {
return;
}
}
}
EOF
# write event names file
cat <<EOF > "lib/src/app/analytics/utilities/event_names.dart"
class EventNames{
static const String eventName = "event_name";
}
EOF
# write Screen names file
cat <<EOF > "lib/src/app/analytics/utilities/page_names.dart"
class PageNames{
static const String pageName = "page_name";
}
EOF
printf "\n\nDon't forget to register the service from initial bindings"