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