diff --git a/client/web/package.json b/client/web/package.json index bdaf001e..96b366db 100644 --- a/client/web/package.json +++ b/client/web/package.json @@ -18,7 +18,7 @@ "check:type": "tsc --noEmit --skipLibCheck", "preinstall": "npx only-allow pnpm", "postinstall": "pnpm plugins:all", - "plugins:new": "ministar createPlugin", + "plugins:new": "tailchat create client-plugin", "plugins:all": "ministar buildPlugin all", "plugins:watch": "ministar watchPlugin all", "plugins:declaration:generate": "cross-env TS_NODE_PROJECT='tsconfig.node.json' ts-node ./scripts/generate-plugin-declaration.typescript.ts" diff --git a/client/web/plugins/com.msgbyte.posthog/manifest.json b/client/web/plugins/com.msgbyte.posthog/manifest.json new file mode 100644 index 00000000..bb7a896a --- /dev/null +++ b/client/web/plugins/com.msgbyte.posthog/manifest.json @@ -0,0 +1,9 @@ +{ + "label": "posthog", + "name": "com.msgbyte.posthog", + "url": "/plugins/com.msgbyte.posthog/index.js", + "version": "0.0.0", + "author": "moonrailgun", + "description": "Posthog 数据统计", + "requireRestart": true +} diff --git a/client/web/plugins/com.msgbyte.posthog/package.json b/client/web/plugins/com.msgbyte.posthog/package.json new file mode 100644 index 00000000..b9e2c37b --- /dev/null +++ b/client/web/plugins/com.msgbyte.posthog/package.json @@ -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" + } +} diff --git a/client/web/plugins/com.msgbyte.posthog/src/index.tsx b/client/web/plugins/com.msgbyte.posthog/src/index.tsx new file mode 100644 index 00000000..85305f4b --- /dev/null +++ b/client/web/plugins/com.msgbyte.posthog/src/index.tsx @@ -0,0 +1,28 @@ +import posthog from 'posthog-js'; + +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'); + + const storage = JSON.parse(window.localStorage['$TailchatInstalledPlugins']); + try { + posthog.capture('Report Plugin', { + plugins: storage.rawData, + pluginNum: Array.isArray(storage.rawData) ? storage.rawData.length : 0, + }); + } catch (err) { + posthog.capture('Report Plugin error', { + err: String(err), + storage, + }); + } +}, 2000); diff --git a/client/web/plugins/com.msgbyte.posthog/tsconfig.json b/client/web/plugins/com.msgbyte.posthog/tsconfig.json new file mode 100644 index 00000000..79e593c1 --- /dev/null +++ b/client/web/plugins/com.msgbyte.posthog/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "jsx": "react", + "importsNotUsedAsValues": "error" + } +} diff --git a/client/web/plugins/com.msgbyte.posthog/types/tailchat.d.ts b/client/web/plugins/com.msgbyte.posthog/types/tailchat.d.ts new file mode 100644 index 00000000..49f524ae --- /dev/null +++ b/client/web/plugins/com.msgbyte.posthog/types/tailchat.d.ts @@ -0,0 +1,2 @@ +declare module '@capital/common'; +declare module '@capital/component'; diff --git a/client/web/src/plugin/builtin.ts b/client/web/src/plugin/builtin.ts index ba28cd59..2edb3d5f 100644 --- a/client/web/src/plugin/builtin.ts +++ b/client/web/src/plugin/builtin.ts @@ -1,11 +1,14 @@ import type { PluginManifest } from 'tailchat-shared'; +import _compact from 'lodash/compact'; + +const isOffical = ['nightly.paw.msgbyte.com'].includes(location.host); /** * 内置插件列表 * * 该列表中的插件会被强制安装 */ -export const builtinPlugins: PluginManifest[] = [ +export const builtinPlugins: PluginManifest[] = _compact([ { label: '网页面板插件', name: 'com.msgbyte.webview', @@ -43,4 +46,13 @@ export const builtinPlugins: PluginManifest[] = [ description: '为应用首次打开介绍应用的能力', requireRestart: true, }, -]; + isOffical && { + label: 'posthog', + name: 'com.msgbyte.posthog', + url: '/plugins/com.msgbyte.posthog/index.js', + version: '0.0.0', + author: 'moonrailgun', + description: 'Posthog 数据统计', + requireRestart: true, + }, +]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 31e5ac34..57f64d77 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -627,6 +627,19 @@ importers: client/web/plugins/com.msgbyte.openapi: specifiers: {} + client/web/plugins/com.msgbyte.posthog: + specifiers: + '@types/styled-components': ^5.1.26 + posthog-js: ^1.35.0 + react: 18.2.0 + styled-components: ^5.3.6 + dependencies: + posthog-js: 1.35.0 + devDependencies: + '@types/styled-components': 5.1.26 + react: 18.2.0 + styled-components: 5.3.6_react@18.2.0 + client/web/plugins/com.msgbyte.snapdrop: specifiers: {} @@ -7065,6 +7078,11 @@ packages: engines: {node: '>=6'} dev: false + /@sentry/types/7.20.0: + resolution: {integrity: sha512-x17ddduGWqW95neBFVvxzmInb5WXVw+2PcNASHXpGFhi7v2gz2a7/w2CcIKxsqODNnc+z/k1t0Y+uy9B6aH6ag==} + engines: {node: '>=8'} + dev: false + /@sentry/utils/6.19.7: resolution: {integrity: sha512-z95ECmE3i9pbWoXQrD/7PgkBAzJYR+iXtPuTkpBjDKs86O3mT+PXOT3BAn79w2wkn7/i3vOGD2xVr1uiMl26dA==} engines: {node: '>=6'} @@ -11674,7 +11692,7 @@ packages: babel-plugin-syntax-jsx: 6.18.0 lodash: 4.17.21 picomatch: 2.3.1 - styled-components: 5.3.6_7i5myeigehqah43i5u7wbekgba + styled-components: 5.3.6_react@18.2.0 /babel-plugin-syntax-jsx/6.18.0: resolution: {integrity: sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==} @@ -16594,6 +16612,10 @@ packages: resolution: {integrity: sha512-uJQyMrX5IJZkhoEUBQ3EjxkeiZkppBd5jS/fMTJmfZxLSiaQjv2zD0kTvuvkSH89uFvgSlB6ueGpjD3HWN7Bxw==} dev: true + /fflate/0.4.8: + resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==} + dev: false + /figgy-pudding/3.5.2: resolution: {integrity: sha512-0btnI/H8f2pavGMN8w40mlSKOfTK2SVJmBfBeVIj3kNw0swwgzyRq0d5TJVOwodFmtvpPeWPN/MCcfuWF0Ezbw==} dev: true @@ -24588,6 +24610,14 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.2 + /posthog-js/1.35.0: + resolution: {integrity: sha512-eRAT+IH0t6M/LH3OygD3mobbr90620O7c0zrxJKKx6REvyzxYMSxjehwPEjFqBess2HJOLWLWSHq146h3EZeOw==} + dependencies: + '@sentry/types': 7.20.0 + fflate: 0.4.8 + rrweb-snapshot: 1.1.14 + dev: false + /precision/1.0.1: resolution: {integrity: sha512-cBMxnM2nzEF1xx75NhhOaKjsDNt92WUZv17t/p3wrvCfA+2RL0twbgfvXvgDbxxsfUUb5C5he5tla8Xa2ny1Ew==} engines: {node: '>=0.10.0'} @@ -27654,6 +27684,10 @@ packages: round-precision: 1.0.0 dev: false + /rrweb-snapshot/1.1.14: + resolution: {integrity: sha512-eP5pirNjP5+GewQfcOQY4uBiDnpqxNRc65yKPW0eSoU1XamDfc4M8oqpXGMyUyvLyxFDB0q0+DChuxxiU2FXBQ==} + dev: false + /rsvp/4.8.5: resolution: {integrity: sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==} engines: {node: 6.* || >= 7.*} @@ -28991,6 +29025,7 @@ packages: react-is: 18.2.0 shallowequal: 1.1.0 supports-color: 5.5.0 + dev: false /styled-components/5.3.6_mdz3marskokvq6744hhidi3r5a: resolution: {integrity: sha512-hGTZquGAaTqhGWldX7hhfzjnIYBZ0IXQXkCYdvF1Sq3DsUaLx6+NTHC5Jj1ooM2F68sBiVz3lvhfwQs/S3l6qg==} @@ -29036,7 +29071,6 @@ packages: react: 18.2.0 shallowequal: 1.1.0 supports-color: 5.5.0 - dev: true /styled-system/5.1.5: resolution: {integrity: sha512-7VoD0o2R3RKzOzPK0jYrVnS8iJdfkKsQJNiLRDjikOpQVqQHns/DXWaPZOH4tIKkhAT7I6wIsy9FWTWh2X3q+A==}