feat(cli): add disable analytics option (#496)

This commit is contained in:
Aman Varshney
2025-08-12 08:21:26 +05:30
committed by GitHub
parent 75b0919399
commit 3c00c5453f
7 changed files with 46 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
add disable analytics option

View File

@@ -178,7 +178,7 @@ export async function createProjectHandler(
), ),
); );
await trackProjectCreation(config); await trackProjectCreation(config, input.disableAnalytics);
const elapsedTimeMs = Date.now() - startTime; const elapsedTimeMs = Date.now() - startTime;
const elapsedTimeInSeconds = (elapsedTimeMs / 1000).toFixed(2); const elapsedTimeInSeconds = (elapsedTimeMs / 1000).toFixed(2);

View File

@@ -90,6 +90,11 @@ export const router = t.router({
webDeploy: WebDeploySchema.optional(), webDeploy: WebDeploySchema.optional(),
directoryConflict: DirectoryConflictSchema.optional(), directoryConflict: DirectoryConflictSchema.optional(),
renderTitle: z.boolean().optional(), renderTitle: z.boolean().optional(),
disableAnalytics: z
.boolean()
.optional()
.default(false)
.describe("Disable analytics"),
}), }),
]), ]),
) )
@@ -198,6 +203,7 @@ export function createBtsCli() {
* packageManager: "bun", * packageManager: "bun",
* install: false, * install: false,
* directoryConflict: "increment", // auto-handle conflicts * directoryConflict: "increment", // auto-handle conflicts
* disableAnalytics: true, // disable analytics
* }); * });
* *
* if (result.success) { * if (result.success) {

View File

@@ -134,6 +134,7 @@ export type CreateInput = {
webDeploy?: WebDeploy; webDeploy?: WebDeploy;
directoryConflict?: DirectoryConflict; directoryConflict?: DirectoryConflict;
renderTitle?: boolean; renderTitle?: boolean;
disableAnalytics?: boolean;
}; };
export type AddInput = { export type AddInput = {

View File

@@ -5,8 +5,8 @@ import { isTelemetryEnabled } from "./telemetry";
const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || ""; const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
const POSTHOG_HOST = process.env.POSTHOG_HOST; const POSTHOG_HOST = process.env.POSTHOG_HOST;
export async function trackProjectCreation(config: ProjectConfig) { export async function trackProjectCreation(config: ProjectConfig, disableAnalytics = false) {
if (!isTelemetryEnabled()) return; if (!isTelemetryEnabled() || disableAnalytics) return;
const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`; const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`;
// biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties // biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties

View File

@@ -213,6 +213,18 @@ describe("Programmatic API - Fast Tests", () => {
addons: ["biome"], addons: ["biome"],
}); });
}, 15000); }, 15000);
test("creates project with analytics disabled", async () => {
const result = await init("no-analytics-app", {
yes: true,
disableAnalytics: true,
install: false,
git: false,
});
expect(result.success).toBe(true);
expect(result.projectConfig.projectName).toBe("no-analytics-app");
}, 15000);
}); });
describe("Error scenarios", () => { describe("Error scenarios", () => {

View File

@@ -36,6 +36,7 @@ async function createProject() {
auth: true, auth: true,
packageManager: "bun", packageManager: "bun",
install: false, // Don't install deps automatically install: false, // Don't install deps automatically
disableAnalytics: true, // Disable analytics
}); });
if (result.success) { if (result.success) {
@@ -62,6 +63,23 @@ const result = await init("existing-folder", {
}); });
``` ```
### Disabling Analytics
You can disable analytics:
```typescript
import { init } from "create-better-t-stack";
const result = await init("my-private-project", {
yes: true,
disableAnalytics: true, // No analytics data will be sent
frontend: ["tanstack-router"],
backend: "hono",
});
```
> **Note:** Analytics help improve Better-T Stack by providing insights into usage patterns. When disabled, no data is collected or transmitted.
## API Reference ## API Reference
### `init(projectName?, options?)` ### `init(projectName?, options?)`
@@ -130,6 +148,7 @@ interface CreateInput {
webDeploy?: WebDeploy; // Web deployment setup webDeploy?: WebDeploy; // Web deployment setup
directoryConflict?: DirectoryConflict; // "merge" | "overwrite" | "increment" | "error" directoryConflict?: DirectoryConflict; // "merge" | "overwrite" | "increment" | "error"
renderTitle?: boolean; // Show ASCII art title renderTitle?: boolean; // Show ASCII art title
disableAnalytics?: boolean; // Disable analytics and telemetry
} }
``` ```