1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Integrate analytics stubs (#7186)

* Add matrix-analytics-events as a dependency
* Make IEvent look like a stub definition
* Update pageview tracking to track screens, using a hypothetical definition of a screen event
* Remove distinction between pseudo and anon tracking, will need to rework it considering stubs
This commit is contained in:
James Salter
2021-12-06 21:43:42 +11:00
committed by GitHub
parent 684b0617ae
commit 43f264ccfc
7 changed files with 101 additions and 148 deletions

View File

@ -39,7 +39,7 @@ describe('DecryptionFailureTracker', function() {
const failedDecryptionEvent = createFailedDecryptionEvent();
let count = 0;
const tracker = new DecryptionFailureTracker((total) => count += total);
const tracker = new DecryptionFailureTracker((total) => count += total, () => "UnknownError");
const err = new MockDecryptionError();
tracker.eventDecrypted(failedDecryptionEvent, err);
@ -59,7 +59,7 @@ describe('DecryptionFailureTracker', function() {
const decryptedEvent = createFailedDecryptionEvent();
const tracker = new DecryptionFailureTracker((total) => {
expect(true).toBe(false, 'should not track an event that has since been decrypted correctly');
});
}, () => "UnknownError");
const err = new MockDecryptionError();
tracker.eventDecrypted(decryptedEvent, err);
@ -81,7 +81,7 @@ describe('DecryptionFailureTracker', function() {
const decryptedEvent2 = createFailedDecryptionEvent();
let count = 0;
const tracker = new DecryptionFailureTracker((total) => count += total);
const tracker = new DecryptionFailureTracker((total) => count += total, () => "UnknownError");
// Arbitrary number of failed decryptions for both events
const err = new MockDecryptionError();
@ -112,7 +112,7 @@ describe('DecryptionFailureTracker', function() {
const decryptedEvent = createFailedDecryptionEvent();
let count = 0;
const tracker = new DecryptionFailureTracker((total) => count += total);
const tracker = new DecryptionFailureTracker((total) => count += total, () => "UnknownError");
// Indicate decryption
const err = new MockDecryptionError();
@ -140,7 +140,7 @@ describe('DecryptionFailureTracker', function() {
const decryptedEvent = createFailedDecryptionEvent();
let count = 0;
const tracker = new DecryptionFailureTracker((total) => count += total);
const tracker = new DecryptionFailureTracker((total) => count += total, () => "UnknownError");
// Indicate decryption
const err = new MockDecryptionError();
@ -153,7 +153,7 @@ describe('DecryptionFailureTracker', function() {
tracker.trackFailures();
// Simulate the browser refreshing by destroying tracker and creating a new tracker
const secondTracker = new DecryptionFailureTracker((total) => count += total);
const secondTracker = new DecryptionFailureTracker((total) => count += total, () => "UnknownError");
//secondTracker.loadTrackedEventHashMap();
@ -170,28 +170,29 @@ describe('DecryptionFailureTracker', function() {
const counts = {};
const tracker = new DecryptionFailureTracker(
(total, errorCode) => counts[errorCode] = (counts[errorCode] || 0) + total,
(error) => error === "UnknownError" ? "UnknownError" : "OlmKeysNotSentError",
);
// One failure of ERROR_CODE_1, and effectively two for ERROR_CODE_2
tracker.addDecryptionFailure(new DecryptionFailure('$event_id1', 'ERROR_CODE_1'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id2', 'ERROR_CODE_2'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id2', 'ERROR_CODE_2'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id3', 'ERROR_CODE_2'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id1', 'UnknownError'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id2', 'OlmKeysNotSentError'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id2', 'OlmKeysNotSentError'));
tracker.addDecryptionFailure(new DecryptionFailure('$event_id3', 'OlmKeysNotSentError'));
// Pretend "now" is Infinity
tracker.checkFailures(Infinity);
tracker.trackFailures();
expect(counts['ERROR_CODE_1']).toBe(1, 'should track one ERROR_CODE_1');
expect(counts['ERROR_CODE_2']).toBe(2, 'should track two ERROR_CODE_2');
expect(counts['UnknownError']).toBe(1, 'should track one UnknownError');
expect(counts['OlmKeysNotSentError']).toBe(2, 'should track two OlmKeysNotSentError');
});
it('should map error codes correctly', () => {
const counts = {};
const tracker = new DecryptionFailureTracker(
(total, errorCode) => counts[errorCode] = (counts[errorCode] || 0) + total,
(errorCode) => 'MY_NEW_ERROR_CODE',
(errorCode) => 'OlmUnspecifiedError',
);
// One failure of ERROR_CODE_1, and effectively two for ERROR_CODE_2
@ -204,7 +205,7 @@ describe('DecryptionFailureTracker', function() {
tracker.trackFailures();
expect(counts['MY_NEW_ERROR_CODE'])
.toBe(3, 'should track three MY_NEW_ERROR_CODE, got ' + counts['MY_NEW_ERROR_CODE']);
expect(counts['OlmUnspecifiedError'])
.toBe(3, 'should track three OlmUnspecifiedError, got ' + counts['OlmUnspecifiedError']);
});
});