Skip to content

Commit 964cac8

Browse files
unix14eyalYaakobi
authored andcommitted
git init
0 parents  commit 964cac8

File tree

15 files changed

+526
-0
lines changed

15 files changed

+526
-0
lines changed

.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.pub/
5+
6+
.idea/
7+
.vagrant/
8+
.sconsign.dblite
9+
.svn/
10+
11+
migrate_working_dir/
12+
13+
*.swp
14+
profile
15+
16+
DerivedData/
17+
18+
.generated/
19+
20+
*.pbxuser
21+
*.mode1v3
22+
*.mode2v3
23+
*.perspectivev3
24+
25+
!default.pbxuser
26+
!default.mode1v3
27+
!default.mode2v3
28+
!default.perspectivev3
29+
30+
xcuserdata
31+
32+
*.moved-aside
33+
34+
*.pyc
35+
*sync/
36+
Icon?
37+
.tags*
38+
39+
build/
40+
.android/
41+
.ios/
42+
.flutter-plugins
43+
.flutter-plugins-dependencies
44+
45+
# Symbolication related
46+
app.*.symbols
47+
48+
# Obfuscation related
49+
app.*.map.json

.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "2e9cb0aa71a386a91f73f7088d115c0d96654829"
8+
channel: "stable"
9+
10+
project_type: module

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# analytix
2+
3+
A Flutter library for custom analitics manager
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter development, view the online
8+
[documentation](https://flutter.dev/).
9+
10+
For instructions integrating Flutter modules to your existing applications,
11+
see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app).

analitix_android.iml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android" name="Android">
5+
<configuration>
6+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
7+
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/.android/gen" />
8+
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/.android/gen" />
9+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/.android/AndroidManifest.xml" />
10+
<option name="RES_FOLDER_RELATIVE_PATH" value="/.android/res" />
11+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/.android/assets" />
12+
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/.android/libs" />
13+
<option name="PROGUARD_LOGS_FOLDER_RELATIVE_PATH" value="/.android/proguard_logs" />
14+
</configuration>
15+
</facet>
16+
</component>
17+
<component name="NewModuleRootManager" inherit-compiler-output="true">
18+
<exclude-output />
19+
<content url="file://$MODULE_DIR$/.android">
20+
<sourceFolder url="file://$MODULE_DIR$/.android/Flutter/src/main/java" isTestSource="false" />
21+
<sourceFolder url="file://$MODULE_DIR$/.android/gen" isTestSource="false" generated="true" />
22+
</content>
23+
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
24+
<orderEntry type="sourceFolder" forTests="false" />
25+
<orderEntry type="library" name="Flutter for Android" level="project" />
26+
</component>
27+
</module>

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
3+
import 'package:analitix/analitix/abstract/base_reporter.dart';
4+
import 'package:analitix/analitix/reporters/custom_reporter.dart';
5+
import 'package:analitix/analitix/reporters/printer_reporter.dart';
6+
7+
import '../models/analytix_event.dart';
8+
import '../reporters/excel_reporter.dart';
9+
10+
class AnalytixManager {
11+
12+
static final AnalytixManager _instance = AnalytixManager._internal();
13+
14+
bool _isCollectionEnabled = true;
15+
String? _screenName;
16+
String? _userId;
17+
Map<String, dynamic> _userProperties = {}; /// todo add device properties collection
18+
List<AnalytixEvent> _allEvents = [];
19+
20+
factory AnalytixManager() {
21+
return _instance;
22+
}
23+
24+
AnalytixManager._internal();
25+
26+
List<BaseReporter> reporters = [
27+
PrinterReporter(),
28+
CustomReporter(),
29+
ExcelReporter(),
30+
];
31+
32+
void init() {
33+
print('AnalytixManager init');
34+
}
35+
36+
void logEvent(String name, String subEventName, Map<String, dynamic> params) {
37+
if(!_isCollectionEnabled) {
38+
print('AnalytixManager logEvent: Collection is disabled');
39+
return;
40+
}
41+
print('AnalytixManager logEvent: $name, $params');
42+
43+
for(BaseReporter reporter in reporters) {
44+
params['screenName'] = _screenName;
45+
params['userId'] = _userId;
46+
params['userProperties'] = _userProperties;
47+
var newEvent = AnalytixEvent(name, subEventName: subEventName, parameters: params);
48+
reporter.logEvent(newEvent);
49+
_allEvents.add(newEvent);
50+
}
51+
}
52+
53+
void setUserProperty(String name, dynamic value) {
54+
print('AnalytixManager setUserProperty: $name, $value');
55+
_userProperties[name] = value;
56+
}
57+
58+
void setUserId(String userId) {
59+
print('AnalytixManager setUserId: $userId');
60+
_userId = userId;
61+
}
62+
63+
void setScreenName(String name) {
64+
print('AnalytixManager setScreenName: $name');
65+
_screenName = name;
66+
}
67+
68+
void setAnalyticsCollectionEnabled(bool enabled) {
69+
print('AnalytixManager setAnalyticsCollectionEnabled: $enabled');
70+
_isCollectionEnabled = enabled;
71+
}
72+
73+
void resetAnalyticsData() {
74+
print('AnalytixManager resetAnalyticsData');
75+
_userId = null;
76+
_screenName = null;
77+
_userProperties = {};
78+
_allEvents.clear();
79+
}
80+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import '../models/analytix_event.dart';
3+
4+
abstract class BaseReporter {
5+
void init();
6+
void logEvent(AnalytixEvent event);
7+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'dart:io';
2+
import 'package:analitix/analitix/models/analytix_event.dart';
3+
import 'package:flutter/foundation.dart';
4+
import 'package:csv/csv.dart';
5+
6+
extension FileExtension on File {
7+
8+
/// This function saves the analytics events into a CSV file
9+
Future<File?> exportToCsv(List<AnalytixEvent> events) async {
10+
// Convert the list of TroubleshootHistoryItem to a list of lists
11+
final rows = events.map((item) => [item.eventName, item.subEventName, item.parameters]).toList();
12+
13+
// Convert the list of lists to a CSV string
14+
String csv = const ListToCsvConverter().convert(rows);
15+
16+
// Write the CSV string to the file
17+
await writeAsString(csv);
18+
19+
if(kDebugMode) {
20+
checkIfFileExist();
21+
}
22+
print("saveEventsIntoFile: File finished");
23+
return this;
24+
}
25+
26+
/// This is a helper function to check if the file was created successfully
27+
Future<bool> checkIfFileExist() async {
28+
// Check if the file exists
29+
bool fileExists = await exists();
30+
if (fileExists) {
31+
print("File successfully created at: $path");
32+
// Read the file contents
33+
String contents = await readAsString();
34+
print("File contents: $contents");
35+
return true;
36+
} else {
37+
print("File not created");
38+
return false;
39+
}
40+
}
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
class AnalytixEvent {
3+
final String eventName;
4+
final String? subEventName;
5+
final Map<String, dynamic>? parameters;
6+
7+
AnalytixEvent(this.eventName, {this.subEventName, this.parameters});
8+
9+
@override
10+
String toString() {
11+
return 'AnalytixEvent: $eventName, subEventName: $subEventName, parameters: $parameters';
12+
}
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import 'dart:io';
3+
import 'package:analitix/analitix/models/analytix_event.dart';
4+
import 'package:path_provider/path_provider.dart';
5+
import '../extensions/file_extension.dart';
6+
import '../abstract/base_reporter.dart';
7+
8+
/// CustomReporter class
9+
/// This class is an example of a custom reporter that extends the BaseReporter class
10+
/// we can add custom logic to this class
11+
/// For example, we can use it in order to implement a 3rd party analytics service
12+
/// such as Firebase analytics, Google analytics, Mixpanel, etc.
13+
/// or to send the events to a custom server
14+
class CustomReporter extends BaseReporter {
15+
16+
@override
17+
void init() {
18+
print('CustomReporter: init');
19+
/// TODO: implement init
20+
}
21+
22+
@override
23+
void logEvent(AnalytixEvent event) {
24+
print('CustomReporter: logEvent: $event');
25+
/// TODO: implement logEvent
26+
}
27+
}

0 commit comments

Comments
 (0)