Skip to content

Commit e154663

Browse files
authored
Merge pull request #2 from unix14/lib
created a pub dev lib
2 parents e595a8d + 547164b commit e154663

20 files changed

+894
-0
lines changed

analytix/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
5+
# Avoid committing pubspec.lock for library packages; see
6+
# https://dart.dev/guides/libraries/private-files#pubspeclock.
7+
pubspec.lock

analytix/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

analytix/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Eyal Yaakobi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

analytix/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# analytix
2+
3+
A Flutter library for custom analytics management, designed to streamline integration and usage for efficient event tracking and reporting in Dart applications.
4+
5+
## Features
6+
7+
- **Custom Event Tracking**: Easily log and manage events in your application.
8+
- **Screen View Logging**: Track screen views to gain insights into user navigation.
9+
- **Robust Reporting**: Access detailed reports on user interactions and events.
10+
11+
## Getting Started
12+
13+
### Installation
14+
15+
To use the Analytix library, add the following dependency to your `pubspec.yaml` file:
16+
17+
```yaml
18+
dependencies:
19+
analytix: ^1.0.0 # Replace with the latest version
20+
```
21+
22+
### Importing the Library
23+
Import the library in your Dart files:
24+
25+
```dart
26+
import 'package:analitix/analitix.dart';
27+
```
28+
29+
### Basic Usage
30+
Here’s a quick example of how to integrate Analytix into your Flutter application:
31+
32+
```dart
33+
import 'package:flutter/material.dart';
34+
import 'package:analitix/analitix/abstract/analytix_manager.dart';
35+
36+
void main() {
37+
runApp(MyApp());
38+
}
39+
40+
class MyApp extends StatelessWidget {
41+
@override
42+
Widget build(BuildContext context) {
43+
return MaterialApp(
44+
home: SimpleEventExampleScreen(),
45+
);
46+
}
47+
}
48+
49+
class SimpleEventExampleScreen extends StatefulWidget {
50+
@override
51+
State<SimpleEventExampleScreen> createState() => _SimpleEventExampleScreenState();
52+
}
53+
54+
class _SimpleEventExampleScreenState extends State<SimpleEventExampleScreen> {
55+
int _counter = 0;
56+
57+
@override
58+
void initState() {
59+
super.initState();
60+
AnalytixManager().logScreenView("simple_event_example_screen.dart");
61+
}
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
return Scaffold(
66+
appBar: AppBar(
67+
title: const Text("Analytix Demo"),
68+
),
69+
body: Center(
70+
child: Column(
71+
mainAxisAlignment: MainAxisAlignment.center,
72+
children: <Widget>[
73+
Text('Button pressed: $_counter times'),
74+
ElevatedButton(
75+
onPressed: _incrementCounter,
76+
child: const Text('Press Me'),
77+
),
78+
],
79+
),
80+
),
81+
);
82+
}
83+
84+
void _incrementCounter() {
85+
setState(() {
86+
_counter++;
87+
});
88+
AnalytixManager().logEvent('button_press', 'User pressed the button', params: {'counter': _counter});
89+
}
90+
}
91+
```
92+
93+
## More
94+
95+
For help getting started with Flutter development, view the online
96+
[documentation](https://flutter.dev/).
97+
98+
For instructions integrating Flutter modules to your existing applications,
99+
see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app).

analytix/analysis_options.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
# linter:
19+
# rules:
20+
# - camel_case_types
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:analytix/analytix.dart';
2+
import 'package:analytix/src/abstract/analytix_manager.dart';
3+
4+
5+
void main() {
6+
_initAnalytics();
7+
_testAnalytics();
8+
}
9+
10+
_testAnalytics() {
11+
// Log a screen view
12+
AnalytixManager().logScreenView("HomeScreen");
13+
14+
// Log an event
15+
AnalytixManager().logEvent("button_click", "login_button", params: {
16+
"button_name": "login",
17+
"button_color": "blue",
18+
"button_size": "large",
19+
});
20+
}
21+
22+
_initAnalytics() {
23+
// Init the AnalytixManager
24+
AnalytixManager().init();
25+
26+
// Set the user properties
27+
AnalytixManager().setUserId("1234567890");
28+
AnalytixManager().setUserProperty("name", "Eyal");
29+
AnalytixManager().setUserProperty("last_name", "Yaakobi");
30+
AnalytixManager().setUserProperty("email", "[email protected]");
31+
AnalytixManager().setUserProperty("website", "https://www.3p-cups.com");
32+
AnalytixManager().setUserProperty("isMale", true);
33+
AnalytixManager().setUserProperty("isAdmin", false);
34+
AnalytixManager().setUserProperty("amountOfConnectedSessions", 3);
35+
AnalytixManager().setUserProperty("lastLoginTime", DateTime.now());
36+
AnalytixManager().setUserProperty("refreshToken", "FNvof-Qq3llcnu8nvknerk87@#aaAxz-zZq3");
37+
}

analytix/lib/analytix.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Support for doing something awesome.
2+
///
3+
/// More dartdocs go here.
4+
library;
5+
6+
export 'src/analytix_base.dart';
7+
8+
// TODO: Export any libraries intended for clients of this package.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
3+
4+
import 'package:analytix/src/abstract/base_reporter.dart';
5+
import 'package:analytix/src/reporters/custom_reporter.dart';
6+
import 'package:analytix/src/reporters/printer_reporter.dart';
7+
8+
import '../models/analytix_event.dart';
9+
import '../reporters/excel_reporter.dart';
10+
11+
class AnalytixManager {
12+
13+
static final AnalytixManager _instance = AnalytixManager._internal();
14+
15+
bool _isCollectionEnabled = true;
16+
String? _screenName;
17+
String? _userId;
18+
Map<String, dynamic> _userProperties = {};
19+
Map<String, dynamic> _deviceProperties = {};
20+
final List<AnalytixEvent> _allEvents = [];
21+
22+
factory AnalytixManager() {
23+
return _instance;
24+
}
25+
26+
AnalytixManager._internal();
27+
28+
List<BaseReporter> reporters = [
29+
PrinterReporter(),
30+
CustomReporter(),
31+
ExcelReporter(),
32+
];
33+
34+
void init() {
35+
print('AnalytixManager init');
36+
}
37+
38+
void logScreenView(String screenName) {
39+
print('AnalytixManager setScreenName: $screenName');
40+
_screenName = screenName;
41+
logEvent('screen_view', screenName);
42+
}
43+
44+
void logEvent(String name, String subEventName, {Map<String, dynamic> params = const {} }) {
45+
if(!_isCollectionEnabled) {
46+
print('AnalytixManager logEvent: Collection is disabled');
47+
return;
48+
}
49+
print('AnalytixManager logEvent: $name, $params');
50+
Map<String, dynamic> newParams = {};
51+
newParams.addAll(params);
52+
53+
for(BaseReporter reporter in reporters) {
54+
newParams['screenName'] = _screenName;
55+
newParams['userId'] = _userId;
56+
newParams['userProperties'] = _userProperties;
57+
newParams['deviceProperties'] = _deviceProperties;
58+
newParams['eventTime'] = DateTime.now();
59+
var newEvent = AnalytixEvent(name, subEventName: subEventName, parameters: newParams);
60+
reporter.logEvent(newEvent);
61+
_allEvents.add(newEvent);
62+
}
63+
}
64+
65+
void addReporters(List<BaseReporter> reporters) {
66+
reporters.addAll(reporters);
67+
}
68+
69+
void addReporter(BaseReporter reporter) {
70+
reporters.add(reporter);
71+
}
72+
73+
void removeReporters(List<BaseReporter> reporters) {
74+
reporters.removeWhere((element) => reporters.contains(element));
75+
}
76+
77+
void removeReporter(BaseReporter reporter) {
78+
reporters.remove(reporter);
79+
}
80+
81+
void clearReporters() {
82+
reporters.clear();
83+
}
84+
85+
void setDeviceProperties(Map<String, dynamic> properties) {
86+
print('AnalytixManager setDeviceProperties: $properties');
87+
_userProperties.addAll(properties);
88+
}
89+
90+
void setUserProperty(String name, dynamic value) {
91+
print('AnalytixManager setUserProperty: $name, $value');
92+
_userProperties[name] = value;
93+
}
94+
95+
void setUserId(String userId) {
96+
print('AnalytixManager setUserId: $userId');
97+
_userId = userId;
98+
}
99+
100+
void setAnalyticsCollectionEnabled(bool enabled) {
101+
print('AnalytixManager setAnalyticsCollectionEnabled: $enabled');
102+
_isCollectionEnabled = enabled;
103+
}
104+
105+
void resetAnalyticsData() {
106+
print('AnalytixManager resetAnalyticsData');
107+
_userId = null;
108+
_screenName = null;
109+
_userProperties = {};
110+
_deviceProperties = {};
111+
_allEvents.clear();
112+
}
113+
}
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// TODO: Put public facing types in this file.
2+
3+
/// Checks if you are awesome. Spoiler: you are.
4+
class Awesome {
5+
bool get isAwesome => true;
6+
}

0 commit comments

Comments
 (0)