Skip to content

Commit c8371f5

Browse files
committed
chore: update tracking meta
1 parent 7aa3701 commit c8371f5

File tree

13 files changed

+76
-29
lines changed

13 files changed

+76
-29
lines changed

src/commands/manipulations/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { window } from 'vscode'
22
import { LocaleTreeItem, ProgressSubmenuItem } from '~/views'
3-
import { CurrentFile, Global, Node, LocaleNode, LocaleRecord } from '~/core'
3+
import { CurrentFile, Global, Node, LocaleNode, LocaleRecord, ActionSource } from '~/core'
44
import i18n from '~/i18n'
55

66
export interface CommandOptions {
@@ -9,6 +9,7 @@ export interface CommandOptions {
99
from?: string
1010
locales?: string[]
1111
keyIndex?: number
12+
actionSource?: ActionSource
1213
}
1314

1415
export function getNodeOrRecord(item?: LocaleTreeItem | CommandOptions): LocaleNode | LocaleRecord | undefined {

src/commands/manipulations/editKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Log, promptEdit } from '~/utils'
44
import { Config, CurrentFile, Telemetry, TelemetryKey } from '~/core'
55

66
export async function EditKey(item?: LocaleTreeItem | CommandOptions) {
7-
Telemetry.track(TelemetryKey.EditKey)
7+
Telemetry.track(TelemetryKey.EditKey, { source: Telemetry.getActionSource(item) })
88

99
let node = getNodeOrRecord(item)
1010

src/commands/manipulations/fulfillKeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { window } from 'vscode'
2-
import { ProgressSubmenuItem, LocaleTreeItem } from '~/views'
32
import { CommandOptions } from './common'
3+
import { ProgressSubmenuItem, LocaleTreeItem } from '~/views'
44
import { Global, PendingWrite, CurrentFile } from '~/core'
55
import i18n from '~/i18n'
66

src/commands/manipulations/gotoKey.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { workspace, window, Selection, TextEditorRevealType, commands } from 'vs
33
import { CommandOptions, getNodeOrRecord, getRecordFromNode } from './common'
44
import { LocaleTreeItem, ProgressRootItem } from '~/views'
55
import { Log, NodeHelper } from '~/utils'
6-
import { Config, Global, CurrentFile, Telemetry, TelemetryKey } from '~/core'
6+
import { Config, Global, CurrentFile, Telemetry, TelemetryKey, ActionSource } from '~/core'
77
import i18n from '~/i18n'
88

99
export async function GoToKey(item?: LocaleTreeItem | CommandOptions | ProgressRootItem) {
10-
Telemetry.track(TelemetryKey.GoToKey)
11-
1210
if (item instanceof ProgressRootItem) {
11+
Telemetry.track(TelemetryKey.GoToKey, { source: ActionSource.TreeView })
1312
const locale = item.locale
1413
const files = CurrentFile.loader.files.filter(f => f.locale === locale).map(f => f.filepath)
1514
let filepath: string| undefined
@@ -31,6 +30,8 @@ export async function GoToKey(item?: LocaleTreeItem | CommandOptions | ProgressR
3130
await window.showTextDocument(document)
3231
}
3332
else {
33+
Telemetry.track(TelemetryKey.GoToKey, { source: Telemetry.getActionSource(item) })
34+
3435
const node = getNodeOrRecord(item)
3536
if (!node)
3637
return
@@ -44,6 +45,8 @@ export async function GoToKey(item?: LocaleTreeItem | CommandOptions | ProgressR
4445
)
4546
}
4647

48+
Telemetry.track(TelemetryKey.GoToKey)
49+
4750
if (!locale)
4851
return
4952

src/commands/manipulations/renameKey.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { overrideConfirm } from '../overrideConfirm'
33
import { LocaleTreeItem } from '~/views'
44
import { Log, keypathValidate } from '~/utils'
55
import i18n from '~/i18n'
6-
import { Node, CurrentFile, Global, Telemetry, TelemetryKey } from '~/core'
6+
import { Node, CurrentFile, Global, Telemetry, TelemetryKey, ActionSource } from '~/core'
77

88
export async function RenameKey(item?: LocaleTreeItem | string) {
9-
Telemetry.track(TelemetryKey.RenameKey)
10-
119
if (!item)
1210
return
1311

12+
Telemetry.track(TelemetryKey.RenameKey, {
13+
source: item instanceof LocaleTreeItem
14+
? ActionSource.TreeView
15+
: ActionSource.UiEditor,
16+
})
17+
1418
let node: Node | undefined
1519

1620
if (typeof item === 'string')

src/commands/manipulations/translateKey.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export async function promptForSourceLocale(defaultLocale: string, node?: Locale
2323
return result.label || defaultLocale
2424
}
2525

26-
export async function TranslateKeys(item?: LocaleTreeItem | ProgressSubmenuItem | CommandOptions) {
27-
Telemetry.track(TelemetryKey.TranslateKey)
28-
26+
export async function TranslateKeys(
27+
item?: LocaleTreeItem | ProgressSubmenuItem | CommandOptions,
28+
) {
2929
let source: string | undefined
3030

3131
if (item && !(item instanceof LocaleTreeItem) && !(item instanceof ProgressSubmenuItem) && item.from) {
@@ -42,6 +42,8 @@ export async function TranslateKeys(item?: LocaleTreeItem | ProgressSubmenuItem
4242
return
4343
}
4444

45+
Telemetry.track(TelemetryKey.TranslateKey, { actionSource: Telemetry.getActionSource(item) })
46+
4547
let nodes: AccaptableTranslateItem[] = []
4648
let targetLocales: string[] | undefined
4749

src/core/Telemetry.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import { Config } from './Config'
55
import { Log } from '~/utils'
66
import { isDev, isProd, isTest } from '~/env'
77
import { Global } from '~/extension'
8+
import { LocaleTreeItem, ProgressSubmenuItem } from '~/views'
9+
import { CommandOptions } from '~/commands/manipulations/common'
810

911
const HEAP_ID_DEV = '1082064308'
1012
const HEAP_ID_PROD = '4118173713'
1113

1214
const HEAP_ID = isProd ? HEAP_ID_PROD : HEAP_ID_DEV
1315

1416
export enum TelemetryKey {
17+
Activated = 'activated',
1518
DeleteKey = 'delete_key',
1619
Disabled = 'disabled',
1720
EditKey = 'edit_key',
@@ -21,20 +24,26 @@ export enum TelemetryKey {
2124
ExtractStringBulk = 'extract_string_bulk',
2225
GoToKey = 'goto_key',
2326
InsertKey = 'insert_key',
27+
Installed = 'installed',
2428
NewKey = 'new_key',
2529
RenameKey = 'rename_key',
2630
ReviewAddComment = 'review_add_comment',
2731
ReviewApplySuggestion = 'review_apply_suggestion',
2832
ReviewApplyTranslation = 'review_apply_translation',
2933
TranslateKey = 'translate_key',
34+
Updated = 'updated',
35+
ReviewEditComment = 'review_edit_comment',
36+
ReviewResolveComment = 'review_resolve_comment'
3037
}
3138

3239
export enum ActionSource {
3340
None = 'none',
3441
CommandPattele = 'command_pattele',
3542
TreeView = 'tree_view',
3643
Hover = 'hover',
37-
ContextMenu = 'context_menu'
44+
ContextMenu = 'context_menu',
45+
UiEditor = 'ui_editor',
46+
Review = 'review'
3847
}
3948

4049
export interface TelemetryEvent {
@@ -63,6 +72,17 @@ export class Telemetry {
6372
return this._id
6473
}
6574

75+
static checkVersionChange() {
76+
const previousVersion = Config.ctx.globalState.get('i18n-ally.previous-version')
77+
78+
if (!previousVersion)
79+
Telemetry.track(TelemetryKey.Installed, { new_version: version })
80+
else if (previousVersion !== version)
81+
Telemetry.track(TelemetryKey.Updated, { new_version: version, previous_version: previousVersion })
82+
83+
Config.ctx.globalState.update('i18n-ally.previous-version', version)
84+
}
85+
6686
static get isEnabled() {
6787
return Config.telemetry && !isTest
6888
}
@@ -119,6 +139,12 @@ export class Telemetry {
119139
}
120140
}
121141

142+
static getActionSource(item?: LocaleTreeItem | ProgressSubmenuItem | CommandOptions) {
143+
return (item instanceof LocaleTreeItem || item instanceof ProgressSubmenuItem)
144+
? ActionSource.TreeView
145+
: item?.actionSource || ActionSource.CommandPattele
146+
}
147+
122148
static async updateUserProperties() {
123149
if (!this.isEnabled)
124150
return

src/core/loaders/LocaleLoader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import fg from 'fast-glob'
44
import _, { uniq, throttle, set } from 'lodash'
55
import fs from 'fs-extra'
66
import { findBestMatch } from 'string-similarity'
7-
import { ReplaceLocale, Log, applyPendingToObject, unflatten, NodeHelper, getCache, setCache } from '~/utils'
87
import { FILEWATCHER_TIMEOUT } from '../../meta'
98
import { ParsedFile, PendingWrite, DirStructure, TargetPickingStrategy } from '../types'
109
import { LocaleTree } from '../Nodes'
1110
import { AllyError, ErrorType } from '../Errors'
1211
import { Analyst, Global, Config } from '..'
12+
import { Telemetry, TelemetryKey } from '../Telemetry'
1313
import { Loader } from './Loader'
14+
import { ReplaceLocale, Log, applyPendingToObject, unflatten, NodeHelper, getCache, setCache } from '~/utils'
1415
import i18n from '~/i18n'
1516

1617
const THROTTLE_DELAY = 1500
@@ -641,6 +642,9 @@ export class LocaleLoader extends Loader {
641642
this.watchOn(pathname)
642643
if (!this.files.length)
643644
window.showWarningMessage(i18n.t('prompt.no_locale_loaded'))
645+
646+
if (this.files.length && this.keys.length)
647+
Telemetry.track(TelemetryKey.Activated)
644648
}
645649
catch (e) {
646650
Log.error(e)

src/editor/hover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { MarkdownString } from 'vscode'
22
import { Commands } from '~/commands'
33
import i18n from '~/i18n'
4-
import { CurrentFile, Global, LocaleRecord, Config } from '~/core'
4+
import { CurrentFile, Global, LocaleRecord, Config, ActionSource } from '~/core'
55
import { decorateLocale, escapeMarkdown, NodeHelper } from '~/utils'
66

77
const EmptyButton = '⠀⠀'
88

99
function makeMarkdownCommand(command: Commands, args: any): string {
10-
return `command:${command}?${encodeURIComponent(JSON.stringify(args))}`
10+
return `command:${command}?${encodeURIComponent(JSON.stringify({ actionSource: ActionSource.Hover, ...args }))}`
1111
}
1212

1313
function formatValue(text: string) {

src/editor/reviewComments.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { comments, CommentController, TextDocument, CancellationToken, Range, Disposable, commands, CommentReply, CommentAuthorInformation, Uri, Comment, MarkdownString, CommentMode, CommentThread } from 'vscode'
22
import { EXT_REVIEW_ID } from '../meta'
3-
import { ExtensionModule } from '~/modules'
43
import { getAvatarFromEmail } from '../utils/shared'
4+
import { ExtensionModule } from '~/modules'
55
import { Commands } from '~/commands'
66
import i18n from '~/i18n'
7-
import { Config, Global, ReviewComment, KeyDetector } from '~/core'
7+
import { Config, Global, ReviewComment, KeyDetector, ActionSource, Telemetry, TelemetryKey } from '~/core'
88
import { Log } from '~/utils'
99

1010
function userToAuthorInfo(user?: {name?: string; email?: string}): CommentAuthorInformation {
@@ -63,16 +63,16 @@ class ReviewCommentProvider implements Disposable {
6363
}
6464

6565
typeIcon = {
66-
approve: '✅ ',
67-
request_change: '❌ ',
68-
comment: '',
66+
'approve': '✅ ',
67+
'request_change': '❌ ',
68+
'comment': '',
6969
'': '',
7070
}
7171

7272
typeComment = {
73-
approve: `*${i18n.t('review.placeholder.approve')}*`,
74-
request_change: `*${i18n.t('review.placeholder.request_change')}*`,
75-
comment: `*${i18n.t('review.placeholder.comment')}*`,
73+
'approve': `*${i18n.t('review.placeholder.approve')}*`,
74+
'request_change': `*${i18n.t('review.placeholder.request_change')}*`,
75+
'comment': `*${i18n.t('review.placeholder.comment')}*`,
7676
'': '',
7777
}
7878

@@ -102,6 +102,7 @@ class ReviewCommentProvider implements Disposable {
102102
return
103103
}
104104

105+
Telemetry.track(TelemetryKey.ReviewAddComment, { source: ActionSource.Review })
105106
await Global.reviews.addComment(info.keypath, info.locale, {
106107
type,
107108
comment: reply.text,
@@ -124,6 +125,7 @@ class ReviewCommentProvider implements Disposable {
124125
return
125126
}
126127

128+
Telemetry.track(TelemetryKey.ReviewResolveComment, { source: ActionSource.Review })
127129
await Global.reviews.resolveComment(info.keypath, info.locale, reply.id)
128130

129131
this.updateThread(thread, info.keypath, info.locale)
@@ -191,7 +193,7 @@ class ReviewCommentProvider implements Disposable {
191193
}
192194
}
193195

194-
const reviewComments: ExtensionModule = (ctx) => {
196+
const reviewComments: ExtensionModule = () => {
195197
const disposableds = []
196198
const controller = comments.createCommentController(EXT_REVIEW_ID, i18n.t('review.title'))
197199
disposableds.push(new ReviewCommentProvider(controller))

0 commit comments

Comments
 (0)