This commit is contained in:
@@ -14,9 +14,9 @@ class AnalyticsService {
|
|||||||
required this.getAccessToken,
|
required this.getAccessToken,
|
||||||
String? anonymousId,
|
String? anonymousId,
|
||||||
String? userId,
|
String? userId,
|
||||||
}) : _apiBaseUrl = apiBaseUrl,
|
}) : _apiBaseUrl = apiBaseUrl,
|
||||||
_anonymousId = anonymousId ?? const Uuid().v4(),
|
_anonymousId = anonymousId ?? const Uuid().v4(),
|
||||||
_userId = userId;
|
_userId = userId;
|
||||||
|
|
||||||
static const _queueKey = 'patbond_analytics_queue';
|
static const _queueKey = 'patbond_analytics_queue';
|
||||||
static const _queueMaxSize = 500;
|
static const _queueMaxSize = 500;
|
||||||
@@ -40,7 +40,10 @@ class AnalyticsService {
|
|||||||
|
|
||||||
/// Tracks event (never throws, never awaits network). Props are validated
|
/// Tracks event (never throws, never awaits network). Props are validated
|
||||||
/// for privacy red-line patterns locally before queuing.
|
/// for privacy red-line patterns locally before queuing.
|
||||||
Future<void> trackEvent(String eventName, [Map<String, dynamic>? props]) async {
|
Future<void> trackEvent(
|
||||||
|
String eventName, [
|
||||||
|
Map<String, dynamic>? props,
|
||||||
|
]) async {
|
||||||
try {
|
try {
|
||||||
if (props != null && _containsForbiddenField(props)) {
|
if (props != null && _containsForbiddenField(props)) {
|
||||||
debugPrint('Analytics: event $eventName rejected (forbidden field)');
|
debugPrint('Analytics: event $eventName rejected (forbidden field)');
|
||||||
@@ -57,7 +60,9 @@ class AnalyticsService {
|
|||||||
'clientTs': DateTime.now().toUtc().toIso8601String(),
|
'clientTs': DateTime.now().toUtc().toIso8601String(),
|
||||||
'appVersion': '1.0.0+1', // TODO: read from package_info_plus
|
'appVersion': '1.0.0+1', // TODO: read from package_info_plus
|
||||||
'platform': Platform.isAndroid ? 'android' : 'ios',
|
'platform': Platform.isAndroid ? 'android' : 'ios',
|
||||||
'osVersion': Platform.isAndroid ? 'android-14' : 'ios-17', // TODO: device_info_plus
|
'osVersion': Platform.isAndroid
|
||||||
|
? 'android-14'
|
||||||
|
: 'ios-17', // TODO: device_info_plus
|
||||||
if (props != null && props.isNotEmpty) 'props': props,
|
if (props != null && props.isNotEmpty) 'props': props,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,9 +95,9 @@ class AnalyticsService {
|
|||||||
if (token != null) 'Authorization': 'Bearer $token',
|
if (token != null) 'Authorization': 'Bearer $token',
|
||||||
};
|
};
|
||||||
|
|
||||||
final request = await HttpClient()
|
final request =
|
||||||
.postUrl(Uri.parse('$_apiBaseUrl/api/v1/events'))
|
await HttpClient().postUrl(Uri.parse('$_apiBaseUrl/api/v1/events'))
|
||||||
..headers.contentType = ContentType.json;
|
..headers.contentType = ContentType.json;
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
request.headers.add('Authorization', 'Bearer $token');
|
request.headers.add('Authorization', 'Bearer $token');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user