11/// The Flutter SDK for Aptabase, a privacy-first and simple analytics platform for apps.
22library aptabase_flutter;
33
4+ import 'dart:math' ;
45import 'package:aptabase_flutter/sys_info.dart' ;
56import 'package:flutter/foundation.dart' ;
67import 'package:universal_io/io.dart' ;
78import 'dart:convert' ;
89import 'dart:developer' as developer;
9- import 'package:uuid/uuid.dart' ;
1010
1111/// Additional options for initializing the Aptabase SDK.
1212class InitOptions {
@@ -19,7 +19,7 @@ class InitOptions {
1919///
2020/// Initialize the client with `Aptabase.init(appKey)` and then use `Aptabase.instance.trackEvent(eventName, props)` to record events.
2121class Aptabase {
22- static const String _sdkVersion = "aptabase_flutter@0.1.0 " ;
22+ static const String _sdkVersion = "aptabase_flutter@0.1.1 " ;
2323 static const Duration _sessionTimeout = Duration (hours: 1 );
2424
2525 static const Map <String , String > _hosts = {
@@ -30,11 +30,11 @@ class Aptabase {
3030 };
3131
3232 static final http = newUniversalHttpClient ();
33- static const uuid = Uuid ();
33+ static final rnd = Random ();
3434 static SystemInfo ? _sysInfo;
3535 static String _appKey = "" ;
3636 static Uri ? _apiUrl;
37- static String _sessionId = uuid. v4 ();
37+ static String _sessionId = newSessionId ();
3838 static DateTime _lastTouchTs = DateTime .now ().toUtc ();
3939
4040 Aptabase ._();
@@ -68,7 +68,7 @@ class Aptabase {
6868 final now = DateTime .now ().toUtc ();
6969 final elapsed = now.difference (_lastTouchTs);
7070 if (elapsed > _sessionTimeout) {
71- _sessionId = uuid. v4 ();
71+ _sessionId = newSessionId ();
7272 }
7373
7474 _lastTouchTs = now;
@@ -141,4 +141,12 @@ class Aptabase {
141141
142142 return Uri .parse ('$baseUrl /api/v0/event' );
143143 }
144+
145+ /// Returns a new session id.
146+ static String newSessionId () {
147+ String epochInSeconds = (DateTime .now ().millisecondsSinceEpoch ~ / 1000 ).toString ();
148+ String random = (rnd.nextInt (100000000 )).toString ().padLeft (8 , '0' );
149+
150+ return epochInSeconds + random;
151+ }
144152}
0 commit comments