mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-07-05 13:47:59 +08:00
fix(analytics): update analytics client version and enhance tracking features
This commit is contained in:
@@ -132,7 +132,7 @@
|
||||
"@aws-sdk/client-s3": "^3.998.0",
|
||||
"@biomejs/biome": "2.2.4",
|
||||
"@cherrystudio/ai-core": "workspace:*",
|
||||
"@cherrystudio/analytics-client": "^1.1.3",
|
||||
"@cherrystudio/analytics-client": "^1.2.0",
|
||||
"@cherrystudio/embedjs": "0.1.31",
|
||||
"@cherrystudio/embedjs-interfaces": "0.1.31",
|
||||
"@cherrystudio/embedjs-libsql": "0.1.31",
|
||||
|
||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -234,8 +234,8 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:packages/aiCore
|
||||
'@cherrystudio/analytics-client':
|
||||
specifier: ^1.1.3
|
||||
version: 1.1.3(typescript@5.8.3)
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0(typescript@5.8.3)
|
||||
'@cherrystudio/embedjs':
|
||||
specifier: 0.1.31
|
||||
version: 0.1.31(@langchain/core@1.0.2(patch_hash=8dc787a82cebafe8b23c8826f25f29aca64fc8b43a0a1878e0010782e4da96ed)(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@2.2.0(@opentelemetry/api@1.9.0))(openai@6.15.0(ws@8.20.0)(zod@4.3.4)))(@langchain/ollama@0.1.6(@langchain/core@1.0.2(patch_hash=8dc787a82cebafe8b23c8826f25f29aca64fc8b43a0a1878e0010782e4da96ed)(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@2.2.0(@opentelemetry/api@1.9.0))(openai@6.15.0(ws@8.20.0)(zod@4.3.4))))(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@2.2.0(@opentelemetry/api@1.9.0))(axios@1.13.2)(cheerio@1.1.2)(handlebars@4.7.8)(openai@6.15.0(ws@8.20.0)(zod@4.3.4))(ws@8.20.0)
|
||||
@@ -1903,8 +1903,8 @@ packages:
|
||||
'@cfworker/json-schema@4.1.1':
|
||||
resolution: {integrity: sha512-gAmrUZSGtKc3AiBL71iNWxDsyUC5uMaKKGdvzYsBoTW/xi42JQHl7eKV2OYzCUqvc+D2RCcf7EXY2iCyFIk6og==}
|
||||
|
||||
'@cherrystudio/analytics-client@1.1.3':
|
||||
resolution: {integrity: sha512-szi7YxGAKfYzyjaPm0KNizLka/z34HlwSw60vRYt/0kEI5+1ZHtZdcSiK39XUUp/KD06/7YGRf6UDbFHXejkOw==}
|
||||
'@cherrystudio/analytics-client@1.2.0':
|
||||
resolution: {integrity: sha512-1HHhodo0+Y48kMSurd8UZBBLfNVSbJ4bFseFTa20wQHqMiVqR4rpByqnQ1OVGVhjcuIM2TQ6ApaTDj7wuHZJUQ==}
|
||||
engines: {node: '>=16.0.0'}
|
||||
peerDependencies:
|
||||
typescript: '>=4.7.0'
|
||||
@@ -13265,7 +13265,7 @@ snapshots:
|
||||
|
||||
'@cfworker/json-schema@4.1.1': {}
|
||||
|
||||
'@cherrystudio/analytics-client@1.1.3(typescript@5.8.3)':
|
||||
'@cherrystudio/analytics-client@1.2.0(typescript@5.8.3)':
|
||||
optionalDependencies:
|
||||
typescript: 5.8.3
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { TokenUsageData } from '@cherrystudio/analytics-client'
|
||||
import { AnalyticsClient } from '@cherrystudio/analytics-client'
|
||||
import { loggerService } from '@logger'
|
||||
import { generateUserAgent } from '@main/utils/systemInfo'
|
||||
import { APP_NAME } from '@shared/config/constant'
|
||||
import { app } from 'electron'
|
||||
|
||||
import { configManager } from './ConfigManager'
|
||||
|
||||
@@ -18,24 +21,45 @@ class AnalyticsService {
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
if (!configManager.getEnableDataCollection()) {
|
||||
logger.info('Data collection is disabled, skipping analytics initialization')
|
||||
return
|
||||
}
|
||||
|
||||
this.client = new AnalyticsClient({
|
||||
clientId: configManager.getClientId(),
|
||||
channel: 'cherry-studio',
|
||||
onError: (error) => logger.error('Analytics error:', error)
|
||||
onError: (error) => logger.error('Analytics error:', error),
|
||||
headers: {
|
||||
'User-Agent': generateUserAgent(),
|
||||
'Client-Id': configManager.getClientId(),
|
||||
'App-Name': APP_NAME,
|
||||
'App-Version': `v${app.getVersion()}`,
|
||||
OS: process.platform
|
||||
}
|
||||
})
|
||||
|
||||
this.client.trackAppLaunch({
|
||||
version: app.getVersion(),
|
||||
os: process.platform
|
||||
})
|
||||
|
||||
logger.info('Analytics service initialized')
|
||||
}
|
||||
|
||||
public trackTokenUsage(data: TokenUsageData): void {
|
||||
if (!this.client) return
|
||||
const enableDataCollection = configManager.getEnableDataCollection()
|
||||
|
||||
if (!this.client || !enableDataCollection) {
|
||||
return
|
||||
}
|
||||
|
||||
this.client.trackTokenUsage(data)
|
||||
}
|
||||
|
||||
public async trackAppUpdate(): Promise<void> {
|
||||
if (!this.client) {
|
||||
return
|
||||
}
|
||||
|
||||
await this.client.trackAppUpdate()
|
||||
}
|
||||
|
||||
public async destroy(): Promise<void> {
|
||||
if (!this.client) return
|
||||
await this.client.destroy()
|
||||
|
||||
@@ -12,6 +12,7 @@ import { autoUpdater } from 'electron-updater'
|
||||
import path from 'path'
|
||||
import semver from 'semver'
|
||||
|
||||
import { analyticsService } from './AnalyticsService'
|
||||
import { configManager } from './ConfigManager'
|
||||
import { windowService } from './WindowService'
|
||||
|
||||
@@ -278,6 +279,8 @@ export default class AppUpdater {
|
||||
}
|
||||
|
||||
public async checkForUpdates() {
|
||||
analyticsService.trackAppUpdate()
|
||||
|
||||
if (isWin && 'PORTABLE_EXECUTABLE_DIR' in process.env) {
|
||||
return {
|
||||
currentVersion: app.getVersion(),
|
||||
|
||||
@@ -20,7 +20,7 @@ import type { LanguageVarious, Shortcut } from '@types'
|
||||
import { ThemeMode } from '@types'
|
||||
import { app } from 'electron'
|
||||
import Store from 'electron-store'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { v7 as uuid } from 'uuid'
|
||||
|
||||
import { locales } from '../utils/locales'
|
||||
|
||||
@@ -276,7 +276,7 @@ export class ConfigManager {
|
||||
let clientId = this.get<string>(ConfigKeys.ClientId)
|
||||
|
||||
if (!clientId) {
|
||||
clientId = uuidv4()
|
||||
clientId = uuid()
|
||||
this.set(ConfigKeys.ClientId, clientId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user