mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
event logging on view page fixes
This commit is contained in:
@@ -3,4 +3,5 @@ import { EventType } from '../enums/eventType';
|
||||
export abstract class EventService {
|
||||
collect: (eventType: EventType, cipherId?: string, uploadImmediately?: boolean) => Promise<any>;
|
||||
uploadEvents: () => Promise<any>;
|
||||
clearEvents: () => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
checkPasswordPromise: Promise<number>;
|
||||
|
||||
private totpInterval: any;
|
||||
private previousCipherId: string;
|
||||
|
||||
constructor(protected cipherService: CipherService, protected totpService: TotpService,
|
||||
protected tokenService: TokenService, protected i18nService: I18nService,
|
||||
@@ -57,7 +58,6 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
protected eventService: EventService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.eventService.collect(EventType.Cipher_ClientViewed);
|
||||
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
||||
this.ngZone.run(async () => {
|
||||
switch (message.command) {
|
||||
@@ -94,6 +94,11 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
await this.totpTick(interval);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
if (this.previousCipherId !== this.cipherId) {
|
||||
this.eventService.collect(EventType.Cipher_ClientViewed, this.cipherId);
|
||||
}
|
||||
this.previousCipherId = this.cipherId;
|
||||
}
|
||||
|
||||
edit() {
|
||||
@@ -104,7 +109,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
this.platformUtilsService.eventTrack('Toggled Password');
|
||||
this.showPassword = !this.showPassword;
|
||||
if (this.showPassword) {
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledPasswordVisible);
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledPasswordVisible, this.cipherId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +117,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
this.platformUtilsService.eventTrack('Toggled Card Code');
|
||||
this.showCardCode = !this.showCardCode;
|
||||
if (this.showCardCode) {
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledCardCodeVisible);
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledCardCodeVisible, this.cipherId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +142,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
const f = (field as any);
|
||||
f.showValue = !f.showValue;
|
||||
if (f.showValue) {
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible);
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipherId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,11 +167,11 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
|
||||
|
||||
if (typeI18nKey === 'password') {
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible);
|
||||
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipherId);
|
||||
} else if (typeI18nKey === 'securityCode') {
|
||||
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode);
|
||||
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, this.cipherId);
|
||||
} else if (aType === 'H_Field') {
|
||||
this.eventService.collect(EventType.Cipher_ClientCopiedHiddenField);
|
||||
this.eventService.collect(EventType.Cipher_ClientCopiedHiddenField, this.cipherId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@ import { EventType } from '../../enums/eventType';
|
||||
export class EventData {
|
||||
type: EventType;
|
||||
cipherId: string;
|
||||
date: string;
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ import { EventType } from '../../enums/eventType';
|
||||
export class EventRequest {
|
||||
type: EventType;
|
||||
cipherId: string;
|
||||
date: string;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ export class EventService implements EventServiceAbstraction {
|
||||
}
|
||||
|
||||
async collect(eventType: EventType, cipherId: string = null, uploadImmediately = false): Promise<any> {
|
||||
const authed = await this.userService.isAuthenticated();
|
||||
if (!authed) {
|
||||
return;
|
||||
}
|
||||
const organizations = await this.userService.getAllOrganizations();
|
||||
if (organizations == null) {
|
||||
return;
|
||||
@@ -52,6 +56,7 @@ export class EventService implements EventServiceAbstraction {
|
||||
const event = new EventData();
|
||||
event.type = eventType;
|
||||
event.cipherId = cipherId;
|
||||
event.date = new Date().toISOString();
|
||||
eventCollection.push(event);
|
||||
await this.storageService.save(ConstantsService.eventCollectionKey, eventCollection);
|
||||
if (uploadImmediately) {
|
||||
@@ -60,6 +65,10 @@ export class EventService implements EventServiceAbstraction {
|
||||
}
|
||||
|
||||
async uploadEvents(): Promise<any> {
|
||||
const authed = await this.userService.isAuthenticated();
|
||||
if (!authed) {
|
||||
return;
|
||||
}
|
||||
const eventCollection = await this.storageService.get<EventData[]>(ConstantsService.eventCollectionKey);
|
||||
if (eventCollection == null || eventCollection.length === 0) {
|
||||
return;
|
||||
@@ -68,11 +77,16 @@ export class EventService implements EventServiceAbstraction {
|
||||
const req = new EventRequest();
|
||||
req.type = e.type;
|
||||
req.cipherId = e.cipherId;
|
||||
req.date = e.date;
|
||||
return req;
|
||||
});
|
||||
try {
|
||||
await this.apiService.postEventsCollect(request);
|
||||
await this.storageService.remove(ConstantsService.eventCollectionKey);
|
||||
this.clearEvents();
|
||||
} catch { }
|
||||
}
|
||||
|
||||
async clearEvents(): Promise<any> {
|
||||
await this.storageService.remove(ConstantsService.eventCollectionKey);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user