mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add posthog analytics
This commit is contained in:
@@ -55,19 +55,20 @@
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.11.0",
|
||||
"consola": "^3.4.2",
|
||||
"execa": "^9.5.3",
|
||||
"execa": "^9.6.0",
|
||||
"fs-extra": "^11.3.0",
|
||||
"globby": "^14.1.0",
|
||||
"gradient-string": "^3.0.0",
|
||||
"handlebars": "^4.7.8",
|
||||
"picocolors": "^1.1.1",
|
||||
"yargs": "^17.7.2"
|
||||
"posthog-node": "^4.18.0",
|
||||
"yargs": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/node": "^22.15.21",
|
||||
"@types/node": "^22.15.23",
|
||||
"@types/yargs": "^17.0.33",
|
||||
"tsdown": "^0.12.3",
|
||||
"tsdown": "^0.12.4",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import { createProject } from "./helpers/project-generation/create-project";
|
||||
import { gatherConfig } from "./prompts/config-prompts";
|
||||
import { getProjectName } from "./prompts/project-name";
|
||||
import type { ProjectConfig } from "./types";
|
||||
import { trackProjectCreation } from "./utils/analytics";
|
||||
import { displayConfig } from "./utils/display-config";
|
||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||
import { renderTitle } from "./utils/render-title";
|
||||
@@ -197,11 +198,13 @@ async function main() {
|
||||
|
||||
await createProject(config);
|
||||
|
||||
await trackProjectCreation(config);
|
||||
|
||||
const reproducibleCommand = generateReproducibleCommand(config);
|
||||
|
||||
log.success(
|
||||
pc.blue(
|
||||
`You can reproduce this setup with the following command:\n${generateReproducibleCommand(
|
||||
config,
|
||||
)}`,
|
||||
`You can reproduce this setup with the following command:\n${reproducibleCommand}`,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
43
apps/cli/src/utils/analytics.ts
Normal file
43
apps/cli/src/utils/analytics.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import consola from "consola";
|
||||
import { PostHog } from "posthog-node";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { getLatestCLIVersion } from "./get-latest-cli-version";
|
||||
|
||||
const POSTHOG_API_KEY = "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs";
|
||||
const POSTHOG_HOST = "https://us.i.posthog.com";
|
||||
|
||||
export async function trackProjectCreation(
|
||||
config: ProjectConfig,
|
||||
): Promise<void> {
|
||||
const posthog = new PostHog(POSTHOG_API_KEY, {
|
||||
host: POSTHOG_HOST,
|
||||
flushAt: 1,
|
||||
flushInterval: 0,
|
||||
privacyMode: true,
|
||||
disableGeoip: true,
|
||||
});
|
||||
|
||||
try {
|
||||
const sessionId = `cli_${Date.now()}_${crypto
|
||||
.randomUUID()
|
||||
.replace(/-/g, "")}`;
|
||||
|
||||
const { projectName, projectDir, relativePath, ...safeConfig } = config;
|
||||
|
||||
posthog.capture({
|
||||
distinctId: sessionId,
|
||||
event: "project_created",
|
||||
properties: {
|
||||
...safeConfig,
|
||||
cli_version: getLatestCLIVersion(),
|
||||
node_version: process.version,
|
||||
platform: process.platform,
|
||||
$ip: null,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
consola.debug("Analytics tracking failed:", error);
|
||||
} finally {
|
||||
await posthog.shutdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user