优化
This commit is contained in:
BIN
client/web/plugins/com.msgbyte.posthog/assets/icon.png
Normal file
BIN
client/web/plugins/com.msgbyte.posthog/assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
11
client/web/plugins/com.msgbyte.posthog/manifest.json
Normal file
11
client/web/plugins/com.msgbyte.posthog/manifest.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"label": "Posthog",
|
||||
"name": "com.msgbyte.posthog",
|
||||
"url": "/plugins/com.msgbyte.posthog/index.js",
|
||||
"icon": "/plugins/com.msgbyte.posthog/assets/icon.png",
|
||||
"version": "0.0.0",
|
||||
"author": "moonrailgun",
|
||||
"description": "Posthog Statistics",
|
||||
"description.zh-CN": "Posthog 数据统计",
|
||||
"requireRestart": true
|
||||
}
|
||||
18
client/web/plugins/com.msgbyte.posthog/package.json
Normal file
18
client/web/plugins/com.msgbyte.posthog/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@plugins/com.msgbyte.posthog",
|
||||
"main": "src/index.tsx",
|
||||
"version": "0.0.0",
|
||||
"description": "Posthog 数据统计",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"sync:declaration": "tailchat declaration github"
|
||||
},
|
||||
"dependencies": {
|
||||
"posthog-js": "^1.35.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/styled-components": "^5.1.26",
|
||||
"react": "18.2.0",
|
||||
"styled-components": "^5.3.6"
|
||||
}
|
||||
}
|
||||
62
client/web/plugins/com.msgbyte.posthog/src/index.tsx
Normal file
62
client/web/plugins/com.msgbyte.posthog/src/index.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import posthog from 'posthog-js';
|
||||
import { sharedEvent } from '@capital/common';
|
||||
|
||||
try {
|
||||
posthog.init('phc_xRCv3qbbOBMQkz31kbYMngXxn7Ey5JMu0BZIFktO6km', {
|
||||
api_host: 'https://app.posthog.com',
|
||||
autocapture: false, // 关闭autocapture以节约事件用量
|
||||
disable_session_recording: true, // 关闭自动录屏(不需要且一直报错)
|
||||
});
|
||||
|
||||
const PLUGIN_NAME = 'posthog';
|
||||
|
||||
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
posthog.capture('Report Plugin', {
|
||||
plugins: list.map((item) => item.name), // 主要收集名称列表
|
||||
pluginNum: list.length,
|
||||
pluginRaw: JSON.stringify(list), // 原始信息
|
||||
});
|
||||
} 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,
|
||||
});
|
||||
});
|
||||
|
||||
sharedEvent.on('appLoaded', () => {
|
||||
// 上报加载耗时
|
||||
posthog.capture('App Loaded', {
|
||||
usage: performance.now(),
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
7
client/web/plugins/com.msgbyte.posthog/tsconfig.json
Normal file
7
client/web/plugins/com.msgbyte.posthog/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"importsNotUsedAsValues": "error"
|
||||
}
|
||||
}
|
||||
2
client/web/plugins/com.msgbyte.posthog/types/tailchat.d.ts
vendored
Normal file
2
client/web/plugins/com.msgbyte.posthog/types/tailchat.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare module '@capital/common';
|
||||
declare module '@capital/component';
|
||||
Reference in New Issue
Block a user