-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New event added for sending analytics within package on errors (#229)
* Added new event + refactoring sentEvent on impl * Fix tests + limiting one error event for logFileStats * Make `Analytics` required for `LogHandler` * Make error sent a field in class * Events added for error handling in session handler * Remove unnecessary `io` import * Refactoring `legacyOptOut` to use loop * Only expose `sentEvents` on the `FakeAnalytics` instance * Bump version * Misc * Convert to wip * Pass send method instead of `Analytics` + nits * `ErrorHandler` class created + used in session * Use `ErrorHandler` with `LogHandler` * Check telemetry status in `Session` * Tests added for the survey handler * Fix error * Tests added for log handler exceptions * Use set for sent error messages * Test added to check for 2 unique error events
- Loading branch information
1 parent
2ef7673
commit 8323b21
Showing
15 changed files
with
734 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'analytics.dart'; | ||
import 'enums.dart'; | ||
import 'event.dart'; | ||
|
||
class ErrorHandler { | ||
/// Stores each of the events that have been sent to GA4 so that the | ||
/// same error doesn't get sent twice. | ||
final Set<Event> _sentErrorEvents = {}; | ||
final SendFunction _sendFunction; | ||
|
||
/// Handles any errors encountered within package:unified_analytics. | ||
ErrorHandler({required SendFunction sendFunction}) | ||
: _sendFunction = sendFunction; | ||
|
||
/// Sends the encountered error [Event.analyticsException] to GA4 backend. | ||
/// | ||
/// This method will not send the event to GA4 if it has already been | ||
/// sent before during the current process. | ||
void log(Event event) { | ||
if (event.eventName != DashEvent.analyticsException || | ||
_sentErrorEvents.contains(event)) { | ||
return; | ||
} | ||
|
||
_sendFunction(event); | ||
_sentErrorEvents.add(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.