Skip to content

Commit 9f3697c

Browse files
feat(cli_tools): Enable override of analytics API URL (#85)
Enable override of the analytics reporting API URL, and of the API call timeout. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Analytics endpoint and request timeout are now configurable parameters with sensible defaults. * **Documentation** * Clarified error handling documentation: only missing files return null, while read/deserialize errors throw exceptions as expected. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 72ed2e1 commit 9f3697c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/cli_tools/lib/src/analytics/analytics.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ abstract interface class Analytics {
1515

1616
/// Analytics service for MixPanel.
1717
class MixPanelAnalytics implements Analytics {
18+
static const _defaultEndpoint = 'https://api.mixpanel.com/track';
19+
static const _defaultTimeout = Duration(seconds: 2);
20+
1821
final String _uniqueUserId;
19-
final String _endpoint = 'https://api.mixpanel.com/track';
22+
final String _endpoint;
2023
final String _projectToken;
2124
final String _version;
25+
final Duration _timeout;
2226

2327
MixPanelAnalytics({
2428
required final String uniqueUserId,
2529
required final String projectToken,
2630
required final String version,
31+
final String endpoint = _defaultEndpoint,
32+
final Duration timeout = _defaultTimeout,
2733
}) : _uniqueUserId = uniqueUserId,
2834
_projectToken = projectToken,
29-
_version = version;
35+
_version = version,
36+
_endpoint = endpoint,
37+
_timeout = timeout;
3038

3139
@override
3240
void cleanUp() {}
@@ -69,7 +77,7 @@ class MixPanelAnalytics implements Analytics {
6977
'Accept': 'text/plain',
7078
'Content-Type': 'application/x-www-form-urlencoded',
7179
},
72-
).timeout(const Duration(seconds: 2));
80+
).timeout(_timeout);
7381
} catch (e) {
7482
return;
7583
}

packages/cli_tools/lib/src/local_storage_manager/local_storage_manager.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ abstract base class LocalStorageManager {
8484
}
8585

8686
/// Tries to fetch and deserialize a json file from the local storage.
87-
/// If the file does not exist or if an error occurs during reading or
88-
/// deserialization, null will be returned.
87+
/// If the file does not exist null will be returned.
8988
///
9089
/// [fileName] The name of the file to fetch.
9190
/// [localStoragePath] The path to the local storage directory.

0 commit comments

Comments
 (0)