mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
refactor and cleanup analytics class
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import Analytics from '../scripts/analytics';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import {
|
||||
@@ -16,7 +17,7 @@ export default class CommandsBackground {
|
||||
private isVivaldi: boolean;
|
||||
|
||||
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
||||
private platformUtilsService: PlatformUtilsService) {
|
||||
private platformUtilsService: PlatformUtilsService, private analytics: Analytics) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.isEdge = this.platformUtilsService.isEdge();
|
||||
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
||||
@@ -68,7 +69,7 @@ export default class CommandsBackground {
|
||||
UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Generated Password From Command',
|
||||
});
|
||||
@@ -85,7 +86,7 @@ export default class CommandsBackground {
|
||||
|
||||
this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
|
||||
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Autofilled From Command',
|
||||
});
|
||||
@@ -98,7 +99,7 @@ export default class CommandsBackground {
|
||||
}
|
||||
|
||||
this.main.openPopup();
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Opened Popup From Command',
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import Analytics from '../scripts/analytics';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import {
|
||||
@@ -13,7 +14,7 @@ export default class ContextMenusBackground {
|
||||
private contextMenus: any;
|
||||
|
||||
constructor(private main: MainBackground, private cipherService: CipherService,
|
||||
private passwordGenerationService: PasswordGenerationService) {
|
||||
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics) {
|
||||
this.contextMenus = chrome.contextMenus;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ export default class ContextMenusBackground {
|
||||
UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Generated Password From Context Menu',
|
||||
});
|
||||
@@ -61,19 +62,19 @@ export default class ContextMenusBackground {
|
||||
}
|
||||
|
||||
if (info.parentMenuItemId === 'autofill') {
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Autofilled From Context Menu',
|
||||
});
|
||||
await this.startAutofillPage(cipher);
|
||||
} else if (info.parentMenuItemId === 'copy-username') {
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Username From Context Menu',
|
||||
});
|
||||
UtilsService.copyToClipboard(cipher.login.username);
|
||||
} else if (info.parentMenuItemId === 'copy-password') {
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Password From Context Menu',
|
||||
});
|
||||
|
||||
@@ -85,6 +85,7 @@ export default class MainBackground {
|
||||
totpService: TotpServiceAbstraction;
|
||||
autofillService: AutofillServiceAbstraction;
|
||||
containerService: ContainerService;
|
||||
analytics: Analytics;
|
||||
|
||||
onUpdatedRan: boolean;
|
||||
onReplacedRan: boolean;
|
||||
@@ -139,6 +140,7 @@ export default class MainBackground {
|
||||
this.autofillService = new AutofillService(this.cipherService, this.tokenService,
|
||||
this.totpService, this.utilsService, this.platformUtilsService);
|
||||
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
||||
this.analytics = new Analytics(window, this.platformUtilsService, this.storageService, this.appIdService);
|
||||
|
||||
// Other fields
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
@@ -147,14 +149,14 @@ export default class MainBackground {
|
||||
|
||||
// Background
|
||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
||||
this.platformUtilsService, this.storageService, this.i18nService);
|
||||
this.platformUtilsService, this.storageService, this.i18nService, this.analytics);
|
||||
this.tabsBackground = new TabsBackground(this, this.platformUtilsService);
|
||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||
this.platformUtilsService);
|
||||
this.platformUtilsService, this.analytics);
|
||||
|
||||
if (!this.isSafari) {
|
||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||
this.passwordGenerationService);
|
||||
this.passwordGenerationService, this.analytics);
|
||||
this.idleBackground = new IdleBackground(this, this.lockService, this.storageService);
|
||||
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService);
|
||||
this.windowsBackground = new WindowsBackground(this);
|
||||
@@ -162,7 +164,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
async bootstrap() {
|
||||
await new Analytics(window).init();
|
||||
this.analytics.ga('send', 'pageview', '/background.html');
|
||||
this.containerService.attachToWindow(window);
|
||||
|
||||
await this.runtimeBackground.init();
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import Analytics from '../scripts/analytics';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import { AutofillService } from '../services/abstractions/autofill.service';
|
||||
@@ -24,7 +25,7 @@ export default class RuntimeBackground {
|
||||
|
||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService,
|
||||
private storageService: StorageService, private i18nService: any) {
|
||||
private storageService: StorageService, private i18nService: any, private analytics: Analytics) {
|
||||
this.isSafari = this.platformUtilsService.isSafari();
|
||||
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
||||
|
||||
@@ -190,7 +191,7 @@ export default class RuntimeBackground {
|
||||
});
|
||||
|
||||
await this.cipherService.saveWithServer(cipher);
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Added Login from Notification Bar',
|
||||
});
|
||||
@@ -284,7 +285,7 @@ export default class RuntimeBackground {
|
||||
await this.reseedStorage();
|
||||
}
|
||||
|
||||
(window as any).ga('send', {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'onInstalled ' + this.onInstalledReason,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user