diff --git a/.changeset/six-pears-joke.md b/.changeset/six-pears-joke.md new file mode 100644 index 0000000..36d0daf --- /dev/null +++ b/.changeset/six-pears-joke.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +Allow disabling telemetry with BTS_TELEMETRY_DISABLED=1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e745b5b..1a0525e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -36,7 +36,7 @@ jobs: with: publish: bun run publish-packages env: - TELEMETRY: "true" + BTS_TELEMETRY: 1 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} diff --git a/apps/cli/README.md b/apps/cli/README.md index 4131859..7b48884 100644 --- a/apps/cli/README.md +++ b/apps/cli/README.md @@ -66,6 +66,32 @@ Options: -h, --help Display help ``` +## Telemetry + +This CLI collects anonymous usage data to help improve the tool. The data collected includes: +- Configuration options selected +- CLI version +- Node.js version +- Platform (OS) + +**Telemetry is enabled by default in published versions** to help us understand usage patterns and improve the tool. + +### Disabling Telemetry + +You can disable telemetry by setting the `BTS_TELEMETRY` environment variable: + +```bash +# Disable telemetry for a single run +BTS_TELEMETRY=0 npx create-better-t-stack my-app + +# Disable telemetry globally in your shell profile (.bashrc, .zshrc, etc.) +export BTS_TELEMETRY=0 +``` + +### Development + +During development, telemetry is automatically disabled when `NODE_ENV=development`. + ## Examples Create a project with default configuration: diff --git a/apps/cli/src/utils/analytics.ts b/apps/cli/src/utils/analytics.ts index a86c68b..e515e43 100644 --- a/apps/cli/src/utils/analytics.ts +++ b/apps/cli/src/utils/analytics.ts @@ -1,6 +1,7 @@ import { PostHog } from "posthog-node"; import type { ProjectConfig } from "../types"; import { getLatestCLIVersion } from "./get-latest-cli-version"; +import { isTelemetryEnabled } from "./telemetry"; const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || ""; const POSTHOG_HOST = process.env.POSTHOG_HOST; @@ -14,7 +15,7 @@ export async function trackProjectCreation( flushInterval: 0, privacyMode: true, disableGeoip: true, - disabled: process.env.TELEMETRY !== "true", + disabled: !isTelemetryEnabled(), }); try { diff --git a/apps/cli/src/utils/telemetry.ts b/apps/cli/src/utils/telemetry.ts new file mode 100644 index 0000000..2be808e --- /dev/null +++ b/apps/cli/src/utils/telemetry.ts @@ -0,0 +1,34 @@ +/** + * Utility function to determine if telemetry should be enabled. + * + * Telemetry is enabled by default in production, but can be disabled by: + * - Setting BTS_TELEMETRY=0 or BTS_TELEMETRY=false + * - Running in development environment (NODE_ENV=development) + */ +export function isTelemetryEnabled(): boolean { + // If user explicitly disabled telemetry + if ( + process.env.BTS_TELEMETRY === "0" || + process.env.BTS_TELEMETRY === "false" + ) { + return false; + } + + // If user explicitly enabled telemetry + if ( + process.env.BTS_TELEMETRY === "1" || + process.env.BTS_TELEMETRY === "true" + ) { + return true; + } + + if ( + process.env.BTS_TELEMETRY_DISABLED === "1" || + process.env.BTS_TELEMETRY_DISABLED === "true" + ) { + return false; + } + + // Default to enabled in production + return true; +} diff --git a/apps/cli/tsdown.config.ts b/apps/cli/tsdown.config.ts index dbbee7f..c4210ce 100644 --- a/apps/cli/tsdown.config.ts +++ b/apps/cli/tsdown.config.ts @@ -10,8 +10,8 @@ export default defineConfig({ banner: "#!/usr/bin/env node", }, env: { - POSTHOG_API_KEY: process.env.POSTHOG_API_KEY || "lol", - POSTHOG_HOST: process.env.POSTHOG_HOST || "lool", - TELEMETRY: process.env.TELEMETRY || "false", // wierd trick i know + POSTHOG_API_KEY: process.env.POSTHOG_API_KEY || "random", + POSTHOG_HOST: process.env.POSTHOG_HOST || "random", + BTS_TELEMETRY: process.env.BTS_TELEMETRY || "0", }, });