mirror of https://github.com/msgbyte/tailchat
perf: sentry和posthog增加try...catch保护
parent
67960ac877
commit
1d924f1692
@ -1,51 +1,55 @@
|
||||
import posthog from 'posthog-js';
|
||||
import { sharedEvent } from '@capital/common';
|
||||
|
||||
posthog.init('phc_xRCv3qbbOBMQkz31kbYMngXxn7Ey5JMu0BZIFktO6km', {
|
||||
api_host: 'https://app.posthog.com',
|
||||
autocapture: false, // 关闭autocapture以节约事件用量
|
||||
disable_session_recording: true, // 关闭自动录屏(不需要且一直报错)
|
||||
});
|
||||
try {
|
||||
posthog.init('phc_xRCv3qbbOBMQkz31kbYMngXxn7Ey5JMu0BZIFktO6km', {
|
||||
api_host: 'https://app.posthog.com',
|
||||
autocapture: false, // 关闭autocapture以节约事件用量
|
||||
disable_session_recording: true, // 关闭自动录屏(不需要且一直报错)
|
||||
});
|
||||
|
||||
const PLUGIN_NAME = 'posthog';
|
||||
|
||||
const PLUGIN_NAME = 'posthog';
|
||||
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
|
||||
|
||||
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
|
||||
setTimeout(() => {
|
||||
console.log('Report plugin install status');
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('Report plugin install status');
|
||||
try {
|
||||
const d = window.localStorage['$TailchatInstalledPlugins'];
|
||||
if (!d) {
|
||||
posthog.capture('Report Plugin', {
|
||||
plugins: [],
|
||||
pluginNum: 0,
|
||||
pluginRaw: '',
|
||||
});
|
||||
return;
|
||||
}
|
||||
const storage = JSON.parse(d);
|
||||
const list = storage.rawData;
|
||||
if (!list || !Array.isArray(list)) {
|
||||
// 格式不匹配
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const d = window.localStorage['$TailchatInstalledPlugins'];
|
||||
if (!d) {
|
||||
posthog.capture('Report Plugin', {
|
||||
plugins: [],
|
||||
pluginNum: 0,
|
||||
pluginRaw: '',
|
||||
plugins: list.map((item) => item.name), // 主要收集名称列表
|
||||
pluginNum: list.length,
|
||||
pluginRaw: JSON.stringify(list), // 原始信息
|
||||
});
|
||||
return;
|
||||
}
|
||||
const storage = JSON.parse(d);
|
||||
const list = storage.rawData;
|
||||
if (!list || !Array.isArray(list)) {
|
||||
// 格式不匹配
|
||||
return;
|
||||
} catch (err) {
|
||||
// Ignore error
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
posthog.capture('Report Plugin', {
|
||||
plugins: list.map((item) => item.name), // 主要收集名称列表
|
||||
pluginNum: list.length,
|
||||
pluginRaw: JSON.stringify(list), // 原始信息
|
||||
sharedEvent.on('loginSuccess', (userInfo) => {
|
||||
posthog.identify(userInfo._id, {
|
||||
email: userInfo.email,
|
||||
username: `${userInfo.nickname}#${userInfo.discriminator}`,
|
||||
avatar: userInfo.avatar,
|
||||
temporary: userInfo.temporary,
|
||||
});
|
||||
} catch (err) {
|
||||
// Ignore error
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
sharedEvent.on('loginSuccess', (userInfo) => {
|
||||
posthog.identify(userInfo._id, {
|
||||
email: userInfo.email,
|
||||
username: `${userInfo.nickname}#${userInfo.discriminator}`,
|
||||
avatar: userInfo.avatar,
|
||||
temporary: userInfo.temporary,
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
Loading…
Reference in New Issue