diff --git a/src/abstractions/platformUtils.service.ts b/src/abstractions/platformUtils.service.ts index acf11779c4f..3ecf6bc521b 100644 --- a/src/abstractions/platformUtils.service.ts +++ b/src/abstractions/platformUtils.service.ts @@ -12,7 +12,6 @@ export abstract class PlatformUtilsService { isSafari: () => boolean; isIE: () => boolean; isMacAppStore: () => boolean; - analyticsId: () => string; isViewOpen: () => Promise; /** * @deprecated This only ever returns null. Pull from your platform's storage using ConstantsService.vaultTimeoutKey @@ -27,7 +26,6 @@ export abstract class PlatformUtilsService { options?: any) => void; showDialog: (body: string, title?: string, confirmText?: string, cancelText?: string, type?: string, bodyIsHtml?: boolean) => Promise; - eventTrack: (action: string, label?: string, options?: any) => void; isDev: () => boolean; isSelfHost: () => boolean; copyToClipboard: (text: string, options?: any) => void; diff --git a/src/angular/components/add-edit.component.ts b/src/angular/components/add-edit.component.ts index a3488780890..02d94eec699 100644 --- a/src/angular/components/add-edit.component.ts +++ b/src/angular/components/add-edit.component.ts @@ -286,7 +286,6 @@ export class AddEditComponent implements OnInit { this.formPromise = this.saveCipher(cipher); await this.formPromise; this.cipher.id = cipher.id; - this.platformUtilsService.eventTrack(this.editMode && !this.cloneMode ? 'Edited Cipher' : 'Added Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t(this.editMode && !this.cloneMode ? 'editedItem' : 'addedItem')); this.onSavedCipher.emit(this.cipher); @@ -369,7 +368,6 @@ export class AddEditComponent implements OnInit { try { this.deletePromise = this.deleteCipher(); await this.deletePromise; - this.platformUtilsService.eventTrack((this.cipher.isDeleted ? 'Permanently ' : '') + 'Deleted Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem')); this.onDeletedCipher.emit(this.cipher); @@ -394,7 +392,6 @@ export class AddEditComponent implements OnInit { try { this.restorePromise = this.restoreCipher(); await this.restorePromise; - this.platformUtilsService.eventTrack('Restored Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem')); this.onRestoredCipher.emit(this.cipher); this.messagingService.send('restoredCipher'); @@ -418,7 +415,6 @@ export class AddEditComponent implements OnInit { } togglePassword() { - this.platformUtilsService.eventTrack('Toggled Password on Edit'); this.showPassword = !this.showPassword; document.getElementById('loginPassword').focus(); if (this.editMode && this.showPassword) { @@ -427,7 +423,6 @@ export class AddEditComponent implements OnInit { } toggleCardCode() { - this.platformUtilsService.eventTrack('Toggled CardCode on Edit'); this.showCardCode = !this.showCardCode; document.getElementById('cardCode').focus(); if (this.editMode && this.showCardCode) { @@ -481,7 +476,6 @@ export class AddEditComponent implements OnInit { return; } - this.platformUtilsService.eventTrack('Check Password'); this.checkPasswordPromise = this.auditService.passwordLeaked(this.cipher.login.password); const matches = await this.checkPasswordPromise; this.checkPasswordPromise = null; diff --git a/src/angular/components/attachments.component.ts b/src/angular/components/attachments.component.ts index 2cf130ab7e5..fdf5f3685c4 100644 --- a/src/angular/components/attachments.component.ts +++ b/src/angular/components/attachments.component.ts @@ -69,7 +69,6 @@ export class AttachmentsComponent implements OnInit { this.formPromise = this.saveCipherAttachment(files[0]); this.cipherDomain = await this.formPromise; this.cipher = await this.cipherDomain.decrypt(); - this.platformUtilsService.eventTrack('Added Attachment'); this.platformUtilsService.showToast('success', null, this.i18nService.t('attachmentSaved')); this.onUploadedAttachment.emit(); } catch { } @@ -96,7 +95,6 @@ export class AttachmentsComponent implements OnInit { try { this.deletePromises[attachment.id] = this.deleteCipherAttachment(attachment.id); await this.deletePromises[attachment.id]; - this.platformUtilsService.eventTrack('Deleted Attachment'); this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedAttachment')); const i = this.cipher.attachments.indexOf(attachment); if (i > -1) { @@ -219,7 +217,6 @@ export class AttachmentsComponent implements OnInit { } } - this.platformUtilsService.eventTrack('Reuploaded Attachment'); this.platformUtilsService.showToast('success', null, this.i18nService.t('attachmentSaved')); this.onReuploadedAttachment.emit(); } catch (e) { diff --git a/src/angular/components/collections.component.ts b/src/angular/components/collections.component.ts index 336334e9c4b..d9433934188 100644 --- a/src/angular/components/collections.component.ts +++ b/src/angular/components/collections.component.ts @@ -64,7 +64,6 @@ export class CollectionsComponent implements OnInit { this.formPromise = this.saveCollections(); await this.formPromise; this.onSavedCollections.emit(); - this.platformUtilsService.eventTrack('Edited Cipher Collections'); this.platformUtilsService.showToast('success', null, this.i18nService.t('editedItem')); } catch { } } diff --git a/src/angular/components/environment.component.ts b/src/angular/components/environment.component.ts index 5a1b5c45628..1232185917f 100644 --- a/src/angular/components/environment.component.ts +++ b/src/angular/components/environment.component.ts @@ -52,7 +52,6 @@ export class EnvironmentComponent { this.notificationsUrl = resUrls.notifications; this.enterpriseUrl = resUrls.enterprise; - this.platformUtilsService.eventTrack('Set Environment URLs'); this.platformUtilsService.showToast('success', null, this.i18nService.t('environmentSaved')); this.saved(); } diff --git a/src/angular/components/export.component.ts b/src/angular/components/export.component.ts index 82b0ca5fb9a..a0b8762c8c6 100644 --- a/src/angular/components/export.component.ts +++ b/src/angular/components/export.component.ts @@ -46,7 +46,6 @@ export class ExportComponent { try { this.formPromise = this.getExportData(); const data = await this.formPromise; - this.platformUtilsService.eventTrack('Exported Data'); this.downloadFile(data); this.saved(); await this.collectEvent(); @@ -74,7 +73,6 @@ export class ExportComponent { } togglePassword() { - this.platformUtilsService.eventTrack('Toggled Master Password on Export'); this.showPassword = !this.showPassword; document.getElementById('masterPassword').focus(); } diff --git a/src/angular/components/folder-add-edit.component.ts b/src/angular/components/folder-add-edit.component.ts index e1008de9c46..89d08e4f7d5 100644 --- a/src/angular/components/folder-add-edit.component.ts +++ b/src/angular/components/folder-add-edit.component.ts @@ -42,7 +42,6 @@ export class FolderAddEditComponent implements OnInit { const folder = await this.folderService.encrypt(this.folder); this.formPromise = this.folderService.saveWithServer(folder); await this.formPromise; - this.platformUtilsService.eventTrack(this.editMode ? 'Edited Folder' : 'Added Folder'); this.platformUtilsService.showToast('success', null, this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder')); this.onSavedFolder.emit(this.folder); @@ -63,7 +62,6 @@ export class FolderAddEditComponent implements OnInit { try { this.deletePromise = this.folderService.deleteWithServer(this.folder.id); await this.deletePromise; - this.platformUtilsService.eventTrack('Deleted Folder'); this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedFolder')); this.onDeletedFolder.emit(this.folder); } catch { } diff --git a/src/angular/components/hint.component.ts b/src/angular/components/hint.component.ts index 914ebfb95bd..354034b553f 100644 --- a/src/angular/components/hint.component.ts +++ b/src/angular/components/hint.component.ts @@ -31,7 +31,6 @@ export class HintComponent { try { this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email)); await this.formPromise; - this.platformUtilsService.eventTrack('Requested Hint'); this.platformUtilsService.showToast('success', null, this.i18nService.t('masterPassSent')); if (this.onSuccessfulSubmit != null) { this.onSuccessfulSubmit(); diff --git a/src/angular/components/lock.component.ts b/src/angular/components/lock.component.ts index d14901e7136..ec9dc4f9d3a 100644 --- a/src/angular/components/lock.component.ts +++ b/src/angular/components/lock.component.ts @@ -164,7 +164,6 @@ export class LockComponent implements OnInit { } togglePassword() { - this.platformUtilsService.eventTrack('Toggled Master Password on Unlock'); this.showPassword = !this.showPassword; document.getElementById(this.pinLock ? 'pin' : 'masterPassword').focus(); } diff --git a/src/angular/components/login.component.ts b/src/angular/components/login.component.ts index 2556ed4f2bc..0a64e38ac17 100644 --- a/src/angular/components/login.component.ts +++ b/src/angular/components/login.component.ts @@ -90,7 +90,6 @@ export class LoginComponent implements OnInit { await this.storageService.remove(Keys.rememberedEmail); } if (response.twoFactor) { - this.platformUtilsService.eventTrack('Logged In To Two-step'); if (this.onSuccessfulLoginTwoFactorNavigate != null) { this.onSuccessfulLoginTwoFactorNavigate(); } else { @@ -102,7 +101,6 @@ export class LoginComponent implements OnInit { if (this.onSuccessfulLogin != null) { this.onSuccessfulLogin(); } - this.platformUtilsService.eventTrack('Logged In'); if (this.onSuccessfulLoginNavigate != null) { this.onSuccessfulLoginNavigate(); } else { @@ -113,7 +111,6 @@ export class LoginComponent implements OnInit { } togglePassword() { - this.platformUtilsService.eventTrack('Toggled Master Password on Login'); this.showPassword = !this.showPassword; document.getElementById('masterPassword').focus(); } diff --git a/src/angular/components/password-generator-history.component.ts b/src/angular/components/password-generator-history.component.ts index 94ad6b1b059..be95fb56739 100644 --- a/src/angular/components/password-generator-history.component.ts +++ b/src/angular/components/password-generator-history.component.ts @@ -23,7 +23,6 @@ export class PasswordGeneratorHistoryComponent implements OnInit { } copy(password: string) { - this.platformUtilsService.eventTrack('Copied Historical Password'); const copyOptions = this.win != null ? { window: this.win } : null; this.platformUtilsService.copyToClipboard(password, copyOptions); this.platformUtilsService.showToast('info', null, diff --git a/src/angular/components/password-generator.component.ts b/src/angular/components/password-generator.component.ts index 982db25adaa..f43cfa11bc9 100644 --- a/src/angular/components/password-generator.component.ts +++ b/src/angular/components/password-generator.component.ts @@ -34,14 +34,12 @@ export class PasswordGeneratorComponent implements OnInit { this.avoidAmbiguous = !this.options.ambiguous; this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password'; this.password = await this.passwordGenerationService.generatePassword(this.options); - this.platformUtilsService.eventTrack('Generated Password'); await this.passwordGenerationService.addHistory(this.password); } async sliderChanged() { this.saveOptions(false); await this.passwordGenerationService.addHistory(this.password); - this.platformUtilsService.eventTrack('Regenerated Password'); } async sliderInput() { @@ -61,11 +59,9 @@ export class PasswordGeneratorComponent implements OnInit { async regenerate() { this.password = await this.passwordGenerationService.generatePassword(this.options); await this.passwordGenerationService.addHistory(this.password); - this.platformUtilsService.eventTrack('Regenerated Password'); } copy() { - this.platformUtilsService.eventTrack('Copied Generated Password'); const copyOptions = this.win != null ? { window: this.win } : null; this.platformUtilsService.copyToClipboard(this.password, copyOptions); this.platformUtilsService.showToast('info', null, @@ -73,7 +69,6 @@ export class PasswordGeneratorComponent implements OnInit { } select() { - this.platformUtilsService.eventTrack('Selected Generated Password'); this.onSelected.emit(this.password); } diff --git a/src/angular/components/password-history.component.ts b/src/angular/components/password-history.component.ts index f227e4ba548..ac99ba76c9b 100644 --- a/src/angular/components/password-history.component.ts +++ b/src/angular/components/password-history.component.ts @@ -18,7 +18,6 @@ export class PasswordHistoryComponent implements OnInit { } copy(password: string) { - this.platformUtilsService.eventTrack('Copied Password History'); const copyOptions = this.win != null ? { window: this.win } : null; this.platformUtilsService.copyToClipboard(password, copyOptions); this.platformUtilsService.showToast('info', null, diff --git a/src/angular/components/premium.component.ts b/src/angular/components/premium.component.ts index b37d4d1f2d2..fa141bad0ca 100644 --- a/src/angular/components/premium.component.ts +++ b/src/angular/components/premium.component.ts @@ -31,7 +31,6 @@ export class PremiumComponent implements OnInit { const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('premiumPurchaseAlert'), this.i18nService.t('premiumPurchase'), this.i18nService.t('yes'), this.i18nService.t('cancel')); if (confirmed) { - this.platformUtilsService.eventTrack('Clicked Purchase Premium'); this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase'); } } @@ -40,7 +39,6 @@ export class PremiumComponent implements OnInit { const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('premiumManageAlert'), this.i18nService.t('premiumManage'), this.i18nService.t('yes'), this.i18nService.t('cancel')); if (confirmed) { - this.platformUtilsService.eventTrack('Clicked Manage Membership'); this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=manage'); } } diff --git a/src/angular/components/register.component.ts b/src/angular/components/register.component.ts index 6149f83f16f..ae45add13de 100644 --- a/src/angular/components/register.component.ts +++ b/src/angular/components/register.component.ts @@ -138,14 +138,12 @@ export class RegisterComponent { try { this.formPromise = this.apiService.postRegister(request); await this.formPromise; - this.platformUtilsService.eventTrack('Registered'); this.platformUtilsService.showToast('success', null, this.i18nService.t('newAccountCreated')); this.router.navigate([this.successRoute], { queryParams: { email: this.email } }); } catch { } } togglePassword(confirmField: boolean) { - this.platformUtilsService.eventTrack('Toggled Master Password on Register'); this.showPassword = !this.showPassword; document.getElementById(confirmField ? 'masterPasswordRetype' : 'masterPassword').focus(); } diff --git a/src/angular/components/set-password.component.ts b/src/angular/components/set-password.component.ts index 5eeabd02f03..a233738db79 100644 --- a/src/angular/components/set-password.component.ts +++ b/src/angular/components/set-password.component.ts @@ -99,7 +99,6 @@ export class SetPasswordComponent extends BaseChangePasswordComponent { } togglePassword(confirmField: boolean) { - this.platformUtilsService.eventTrack('Toggled Master Password on Set Password'); this.showPassword = !this.showPassword; document.getElementById(confirmField ? 'masterPasswordRetype' : 'masterPassword').focus(); } diff --git a/src/angular/components/share.component.ts b/src/angular/components/share.component.ts index 7c9b428296c..8d5b262a671 100644 --- a/src/angular/components/share.component.ts +++ b/src/angular/components/share.component.ts @@ -82,7 +82,6 @@ export class ShareComponent implements OnInit { this.formPromise = this.cipherService.shareWithServer(cipherView, this.organizationId, selectedCollectionIds).then(async () => { this.onSharedCipher.emit(); - this.platformUtilsService.eventTrack('Shared Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t('sharedItem')); }); await this.formPromise; diff --git a/src/angular/components/sso.component.ts b/src/angular/components/sso.component.ts index 94f44040ded..49e8fbce93a 100644 --- a/src/angular/components/sso.component.ts +++ b/src/angular/components/sso.component.ts @@ -138,7 +138,6 @@ export class SsoComponent { this.formPromise = this.authService.logInSso(code, codeVerifier, this.redirectUri); const response = await this.formPromise; if (response.twoFactor) { - this.platformUtilsService.eventTrack('SSO Logged In To Two-step'); if (this.onSuccessfulLoginTwoFactorNavigate != null) { this.onSuccessfulLoginTwoFactorNavigate(); } else { @@ -150,7 +149,6 @@ export class SsoComponent { }); } } else if (response.resetMasterPassword) { - this.platformUtilsService.eventTrack('SSO - routing to complete registration'); if (this.onSuccessfulLoginChangePasswordNavigate != null) { this.onSuccessfulLoginChangePasswordNavigate(); } else { @@ -166,7 +164,6 @@ export class SsoComponent { if (this.onSuccessfulLogin != null) { this.onSuccessfulLogin(); } - this.platformUtilsService.eventTrack('SSO Logged In'); if (this.onSuccessfulLoginNavigate != null) { this.onSuccessfulLoginNavigate(); } else { diff --git a/src/angular/components/two-factor-options.component.ts b/src/angular/components/two-factor-options.component.ts index 88e3ad42c4d..497fb2c18a4 100644 --- a/src/angular/components/two-factor-options.component.ts +++ b/src/angular/components/two-factor-options.component.ts @@ -32,7 +32,6 @@ export class TwoFactorOptionsComponent implements OnInit { } recover() { - this.platformUtilsService.eventTrack('Selected Recover'); this.platformUtilsService.launchUri('https://help.bitwarden.com/article/lost-two-step-device/'); this.onRecoverSelected.emit(); } diff --git a/src/angular/components/two-factor.component.ts b/src/angular/components/two-factor.component.ts index 3a2fa77b549..c3989e8d8af 100644 --- a/src/angular/components/two-factor.component.ts +++ b/src/angular/components/two-factor.component.ts @@ -187,7 +187,6 @@ export class TwoFactorComponent implements OnInit, OnDestroy { if (this.onSuccessfulLogin != null) { this.onSuccessfulLogin(); } - this.platformUtilsService.eventTrack('Logged In From Two-step'); if (response.resetMasterPassword) { this.successRoute = 'set-password'; } diff --git a/src/angular/components/view.component.ts b/src/angular/components/view.component.ts index 76734978eab..a120ebb757f 100644 --- a/src/angular/components/view.component.ts +++ b/src/angular/components/view.component.ts @@ -129,7 +129,6 @@ export class ViewComponent implements OnDestroy, OnInit { try { await this.deleteCipher(); - this.platformUtilsService.eventTrack((this.cipher.isDeleted ? 'Permanently ' : '') + 'Deleted Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem')); this.onDeletedCipher.emit(this.cipher); @@ -152,7 +151,6 @@ export class ViewComponent implements OnDestroy, OnInit { try { await this.restoreCipher(); - this.platformUtilsService.eventTrack('Restored Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem')); this.onRestoredCipher.emit(this.cipher); } catch { } @@ -161,7 +159,6 @@ export class ViewComponent implements OnDestroy, OnInit { } togglePassword() { - this.platformUtilsService.eventTrack('Toggled Password'); this.showPassword = !this.showPassword; if (this.showPassword) { this.eventService.collect(EventType.Cipher_ClientToggledPasswordVisible, this.cipherId); @@ -169,7 +166,6 @@ export class ViewComponent implements OnDestroy, OnInit { } toggleCardCode() { - this.platformUtilsService.eventTrack('Toggled Card Code'); this.showCardCode = !this.showCardCode; if (this.showCardCode) { this.eventService.collect(EventType.Cipher_ClientToggledCardCodeVisible, this.cipherId); @@ -181,7 +177,6 @@ export class ViewComponent implements OnDestroy, OnInit { return; } - this.platformUtilsService.eventTrack('Check Password'); this.checkPasswordPromise = this.auditService.passwordLeaked(this.cipher.login.password); const matches = await this.checkPasswordPromise; @@ -210,7 +205,6 @@ export class ViewComponent implements OnDestroy, OnInit { this.cipherService.updateLastLaunchedDate(cipherId); } - this.platformUtilsService.eventTrack('Launched Login URI'); this.platformUtilsService.launchUri(uri.launchUri); } @@ -219,7 +213,6 @@ export class ViewComponent implements OnDestroy, OnInit { return; } - this.platformUtilsService.eventTrack('Copied ' + aType); const copyOptions = this.win != null ? { window: this.win } : null; this.platformUtilsService.copyToClipboard(value, copyOptions); this.platformUtilsService.showToast('info', null, diff --git a/src/cli/services/cliPlatformUtils.service.ts b/src/cli/services/cliPlatformUtils.service.ts index 8d8dba05af0..2184c991b15 100644 --- a/src/cli/services/cliPlatformUtils.service.ts +++ b/src/cli/services/cliPlatformUtils.service.ts @@ -72,10 +72,6 @@ export class CliPlatformUtilsService implements PlatformUtilsService { return false; } - analyticsId() { - return null as string; - } - isViewOpen() { return Promise.resolve(false); } @@ -118,10 +114,6 @@ export class CliPlatformUtilsService implements PlatformUtilsService { throw new Error('Not implemented.'); } - eventTrack(action: string, label?: string, options?: any) { - throw new Error('Not implemented.'); - } - isDev(): boolean { return process.env.BWCLI_ENV === 'development'; } diff --git a/src/electron/services/electronPlatformUtils.service.ts b/src/electron/services/electronPlatformUtils.service.ts index f7d92e6e147..fd7980d3425 100644 --- a/src/electron/services/electronPlatformUtils.service.ts +++ b/src/electron/services/electronPlatformUtils.service.ts @@ -16,14 +16,12 @@ import { MessagingService } from '../../abstractions/messaging.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { StorageService } from '../../abstractions/storage.service'; -import { AnalyticsIds } from '../../misc/analytics'; import { ElectronConstants } from '../electronConstants'; export class ElectronPlatformUtilsService implements PlatformUtilsService { identityClientId: string; private deviceCache: DeviceType = null; - private analyticsIdCache: string = null; constructor(private i18nService: I18nService, private messagingService: MessagingService, private isDesktopApp: boolean, private storageService: StorageService) { @@ -86,19 +84,6 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService { return isMacAppStore(); } - analyticsId(): string { - if (!this.isDesktopApp) { - return null; - } - - if (this.analyticsIdCache) { - return this.analyticsIdCache; - } - - this.analyticsIdCache = (AnalyticsIds as any)[this.getDevice()]; - return this.analyticsIdCache; - } - isViewOpen(): Promise { return Promise.resolve(false); } @@ -163,14 +148,6 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService { return Promise.resolve(result.response === 0); } - eventTrack(action: string, label?: string, options?: any) { - this.messagingService.send('analyticsEventTrack', { - action: action, - label: label, - options: options, - }); - } - isDev(): boolean { return isDev(); } diff --git a/src/index.ts b/src/index.ts index 36346148dab..d7c0a21d1d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import * as Abstractions from './abstractions'; import * as Enums from './enums'; -import * as Misc from './misc'; import * as Data from './models/data'; import * as Domain from './models/domain'; import * as Request from './models/request'; @@ -8,4 +7,4 @@ import * as Response from './models/response'; import * as View from './models/view'; import * as Services from './services'; -export { Abstractions, Enums, Data, Domain, Misc, Request, Response, Services, View }; +export { Abstractions, Enums, Data, Domain, Request, Response, Services, View }; diff --git a/src/misc/analytics.ts b/src/misc/analytics.ts deleted file mode 100644 index 9fa2276cee4..00000000000 --- a/src/misc/analytics.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { AppIdService } from '../abstractions/appId.service'; -import { PlatformUtilsService } from '../abstractions/platformUtils.service'; -import { StorageService } from '../abstractions/storage.service'; - -import { ConstantsService } from '../services/constants.service'; - -import { DeviceType } from '../enums/deviceType'; - -const GaObj = 'ga'; - -export const AnalyticsIds = { - [DeviceType.ChromeExtension]: 'UA-81915606-6', - [DeviceType.FirefoxExtension]: 'UA-81915606-7', - [DeviceType.OperaExtension]: 'UA-81915606-8', - [DeviceType.EdgeExtension]: 'UA-81915606-9', - [DeviceType.VivaldiExtension]: 'UA-81915606-15', - [DeviceType.SafariExtension]: 'UA-81915606-16', - [DeviceType.WindowsDesktop]: 'UA-81915606-17', - [DeviceType.LinuxDesktop]: 'UA-81915606-19', - [DeviceType.MacOsDesktop]: 'UA-81915606-18', -}; - -export class Analytics { - private gaTrackingId: string = null; - private defaultDisabled = false; - private appVersion: string; - - constructor(win: Window, private gaFilter?: () => boolean, - private platformUtilsService?: PlatformUtilsService, private storageService?: StorageService, - private appIdService?: AppIdService, private dependencyResolver?: () => any) { - if (dependencyResolver != null) { - const deps = dependencyResolver(); - if (platformUtilsService == null && deps.platformUtilsService) { - this.platformUtilsService = deps.platformUtilsService as PlatformUtilsService; - } - if (storageService == null && deps.storageService) { - this.storageService = deps.storageService as StorageService; - } - if (appIdService == null && deps.appIdService) { - this.appIdService = deps.appIdService as AppIdService; - } - } - - this.platformUtilsService.getApplicationVersion().then(v => this.appVersion = v); - this.defaultDisabled = this.platformUtilsService.getDevice() === DeviceType.FirefoxExtension || - this.platformUtilsService.isMacAppStore(); - this.gaTrackingId = this.platformUtilsService.analyticsId(); - - (win as any).GoogleAnalyticsObject = GaObj; - (win as any)[GaObj] = async (action: string, param1: any, param2?: any) => { - await this.ga(action, param1, param2); - }; - } - - async ga(action: string, param1: any, param2?: any) { - return; - - if (this.gaFilter != null && this.gaFilter()) { - return; - } - - const disabled = await this.storageService.get(ConstantsService.disableGaKey); - if ((this.defaultDisabled && disabled == null) || disabled != null && disabled) { - return; - } - - if (action !== 'send' || !param1) { - return; - } - - const gaAnonAppId = await this.appIdService.getAnonymousAppId(); - const version = encodeURIComponent(this.appVersion); - let message = 'v=1&tid=' + this.gaTrackingId + '&cid=' + gaAnonAppId + '&cd1=' + version; - - if (param1 === 'pageview' && param2) { - message += this.gaTrackPageView(param2); - } else if (typeof param1 === 'object' && param1.hitType === 'pageview') { - message += this.gaTrackPageView(param1.page); - } else if (param1 === 'event' && param2) { - message += this.gaTrackEvent(param2); - } else if (typeof param1 === 'object' && param1.hitType === 'event') { - message += this.gaTrackEvent(param1); - } - - const request = new XMLHttpRequest(); - request.open('POST', 'https://www.google-analytics.com/collect', true); - request.send(message); - } - - private gaTrackEvent(options: any) { - return '&t=event&ec=' + (options.eventCategory ? encodeURIComponent(options.eventCategory) : 'Event') + - '&ea=' + encodeURIComponent(options.eventAction) + - (options.eventLabel ? '&el=' + encodeURIComponent(options.eventLabel) : '') + - (options.eventValue ? '&ev=' + encodeURIComponent(options.eventValue) : '') + - (options.page ? '&dp=' + this.cleanPagePath(options.page) : ''); - } - - private gaTrackPageView(pagePath: string) { - return '&t=pageview&dp=' + this.cleanPagePath(pagePath); - } - - private cleanPagePath(pagePath: string) { - const paramIndex = pagePath.indexOf('?'); - if (paramIndex > -1) { - pagePath = pagePath.substring(0, paramIndex); - } - if (pagePath.indexOf('!/') === 0 || pagePath.indexOf('#/') === 0) { - pagePath = pagePath.substring(1); - } - const pathParts = pagePath.split('/'); - const newPathParts: string[] = []; - pathParts.forEach(p => { - if (p.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)) { - newPathParts.push('__guid__'); - } else { - newPathParts.push(p); - } - }); - return encodeURIComponent(newPathParts.join('/')); - } -} diff --git a/src/misc/index.ts b/src/misc/index.ts deleted file mode 100644 index f26abc15fbe..00000000000 --- a/src/misc/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { Analytics } from './analytics';