Skip to content

Commit

Permalink
Improve analytics (hcengineering#4682)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
  • Loading branch information
BykhovDenis authored Feb 16, 2024
1 parent 0c39672 commit 5f7a544
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"@types/jest": "^29.5.5",
"prettier-plugin-svelte": "^3.1.0"
},
"dependencies": {
"@hcengineering/platform": "^0.6.9"
},
"repository": "https://github.com/hcengineering/anticrm",
"publishConfig": {
"registry": "https://npm.pkg.github.com"
Expand Down
9 changes: 9 additions & 0 deletions packages/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright © 2024 Hardcore Engineering Inc
//

import { addEventListener, PlatformEvent, Severity, Status, translate } from '@hcengineering/platform'

export const providers: AnalyticProvider[] = []

export interface AnalyticProvider {
Expand Down Expand Up @@ -51,3 +53,10 @@ export const Analytics = {
})
}
}

addEventListener(PlatformEvent, async (_event, _status: Status) => {
if (_status.severity === Severity.ERROR) {
const label = await translate(_status.code, _status.params, 'en')
Analytics.handleError(new Error(label))
}
})
1 change: 1 addition & 0 deletions packages/platform/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"InternalServerError": "Internal server error",
"MaintenanceWarning": "Maintenance Scheduled in {time, plural, =1 {less than a minute} other {# minutes}}",
"AccountNotFound": "Account not found",
"AccountNotConfirmed": "Account not confirmed",
"WorkspaceNotFound": "Workspace not found",
"InvalidPassword": "Invalid password",
"AccountAlreadyExists": "Account already exists",
Expand Down
1 change: 1 addition & 0 deletions packages/platform/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"InternalServerError": "Внутренняя ошибка сервера",
"MaintenanceWarning": "Серверные работы запланированы через {time, plural, one {# минуту} few {# минуты} other {# минут}}",
"AccountNotFound": "Аккаунт не найден",
"AccountNotConfirmed": "Аккаунт не подтвержден",
"WorkspaceNotFound": "Рабочее пространство не найдено",
"InvalidPassword": "Неверный пароль",
"AccountAlreadyExists": "Аккаунт уже существует",
Expand Down
1 change: 1 addition & 0 deletions packages/platform/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default plugin(platformId, {
InternalServerError: '' as StatusCode,
MaintenanceWarning: '' as StatusCode<{ time: number }>,
AccountNotFound: '' as StatusCode<{ account: string }>,
AccountNotConfirmed: '' as StatusCode<{ account: string }>,
WorkspaceNotFound: '' as StatusCode<{ workspace: string }>,
InvalidPassword: '' as StatusCode<{ account: string }>,
AccountAlreadyExists: '' as StatusCode<{ account: string }>,
Expand Down
2 changes: 2 additions & 0 deletions plugins/login-resources/src/components/Join.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import { checkJoined, join, signUpJoin } from '../utils'
import Form from './Form.svelte'
import { Analytics } from '@hcengineering/analytics'
import presentation from '@hcengineering/presentation'
import { workbenchId } from '@hcengineering/workbench'
import { onMount } from 'svelte'
import login from '../plugin'
const location = getCurrentLocation()
Analytics.handleEvent('invite_link_activated')
let page = 'login'
$: fields =
Expand Down
1 change: 1 addition & 0 deletions plugins/login-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ export async function getInviteLink (expHours: number = 1, emailMask: string = '
body: JSON.stringify(request)
})
const result = await response.json()
Analytics.handleEvent('Get invite link')
return result.result
}

Expand Down
15 changes: 7 additions & 8 deletions server/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,18 @@ export async function upgradeWorkspace (
export const createUserWorkspace =
(version: Data<Version>, txes: Tx[], migrationOperation: [string, MigrateOperation][]) =>
async (db: Db, productId: string, token: string, workspaceName: string): Promise<LoginInfo> => {
const { email, extra } = decodeToken(token)
const nonConfirmed = extra?.confirmed === false
console.log(
`Creating workspace for "${workspaceName}" for ${email} ${nonConfirmed ? 'non confirmed' : 'confirmed'}`
)
const { email } = decodeToken(token)

console.log(`Creating workspace for "${workspaceName}" for ${email}`)

if (nonConfirmed) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: email }))
}
const info = await getAccount(db, email)

if (info === null) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: email }))
}
if (info.confirmed !== true) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotConfirmed, { account: email }))
}

if (info.lastWorkspace !== undefined && info.admin === false) {
if (Date.now() - info.lastWorkspace < 60 * 1000) {
Expand Down

0 comments on commit 5f7a544

Please sign in to comment.