From 16e0cb0f112091238109acf38591af23c7b76b92 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 22 Mar 2024 00:04:18 +0800 Subject: [PATCH] feat: add custom tracker script #37 --- src/server/main.ts | 6 ++++++ src/server/utils/env.ts | 1 + website/docs/website/track-script.md | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/server/main.ts b/src/server/main.ts index 64cc44f..fd4f605 100644 --- a/src/server/main.ts +++ b/src/server/main.ts @@ -66,6 +66,12 @@ app.use('/serverStatus', serverStatusRouter); app.use('/trpc', trpcExpressMiddleware); +if (env.customTrackerScriptName) { + app.get(`/${env.customTrackerScriptName}`, (req, res) => + res.sendFile(path.resolve(__dirname, './public/tracker.js')) + ); +} + if (env.allowOpenapi) { app.use('/open/_ui', swaggerUI.serve, swaggerUI.setup(trpcOpenapiDocument)); app.use('/open/_document', (req, res) => res.send(trpcOpenapiDocument)); diff --git a/src/server/utils/env.ts b/src/server/utils/env.ts index cdbf673..1959a12 100644 --- a/src/server/utils/env.ts +++ b/src/server/utils/env.ts @@ -14,6 +14,7 @@ export const env = { disableAnonymousTelemetry: checkEnvTrusty( process.env.DISABLE_ANONYMOUS_TELEMETRY ), + customTrackerScriptName: process.env.CUSTOM_TRACKER_SCRIPT_NAME, }; export function checkEnvTrusty(env: string | undefined): boolean { diff --git a/website/docs/website/track-script.md b/website/docs/website/track-script.md index 0489b3b..e890e02 100644 --- a/website/docs/website/track-script.md +++ b/website/docs/website/track-script.md @@ -31,3 +31,21 @@ for example: ``` Now, when user click this button, your dashboard will receive new event + + +## Modify default script name + +> This feature available on v1.7.4+ + +You can use environment `CUSTOM_TRACKER_SCRIPT_NAME` when you start it + +for example: +``` +CUSTOM_TRACKER_SCRIPT_NAME="my-tracker.js" +``` + +then you can visit your tracker script with `"https:///my-tracker.js"` + +This is to help you avoid some ad-blockers. + +You do not need the `.js` suffix. It can be any path you choose, even you can use as `CUSTOM_TRACKER_SCRIPT_NAME="this/is/very/long/path"`