Skip to content

Commit 85eb4f0

Browse files
authored
Merge pull request #1 from CodeAnt-AI/feat/set-telemetry
Add telemetry opt-out flag
2 parents 986bc4d + a20d84a commit 85eb4f0

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [0.3.4] - 25/03/2026
4+
- Telemetry opt-out flag
5+
36
## [0.3.3] - 25/03/2026
47
- Bug fixes
58

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeant-cli",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Code review CLI tool",
55
"type": "module",
66
"bin": {

src/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Review from './commands/review.js';
1313
import Welcome from './components/Welcome.js';
1414
import * as scm from './scm/index.js';
1515
import { setConfigValue } from './utils/config.js';
16-
import { track, shutdown as analyticsShutdown } from './utils/analytics.js';
16+
import { track, shutdown as analyticsShutdown, isTelemetryDisabled } from './utils/analytics.js';
1717

1818
// Read version from package.json
1919
const require = createRequire(import.meta.url);
@@ -344,6 +344,28 @@ program
344344
}));
345345
});
346346

347+
// ─── Telemetry control ───
348+
program
349+
.command('set-telemetry <enabled>')
350+
.description('Enable or disable telemetry / PostHog analytics (true or false)')
351+
.action((enabled) => {
352+
const val = enabled.toLowerCase();
353+
if (val !== 'true' && val !== 'false') {
354+
console.error('Usage: codeant set-telemetry <true|false>');
355+
process.exit(1);
356+
}
357+
setConfigValue('telemetryEnabled', val === 'true');
358+
console.log(`Telemetry ${val === 'true' ? 'enabled' : 'disabled'}.`);
359+
});
360+
361+
program
362+
.command('get-telemetry')
363+
.description('Show current telemetry status')
364+
.action(() => {
365+
const disabled = isTelemetryDisabled();
366+
console.log(`Telemetry is currently ${disabled ? 'disabled' : 'enabled'}.`);
367+
});
368+
347369
// ─── Analytics tracking (for external callers like Claude Code skills) ───
348370
program
349371
.command('track')

src/utils/analytics.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const POSTHOG_HOST = 'https://r.codeant.ai';
66

77
let client = null;
88

9+
/** Check if telemetry is disabled via env var or config. */
10+
export function isTelemetryDisabled() {
11+
const envVal = process.env.CODEANT_TELEMETRY_DISABLED;
12+
if (envVal !== undefined) {
13+
return envVal === '1' || envVal.toLowerCase() === 'true';
14+
}
15+
return getConfigValue('telemetryEnabled') === false;
16+
}
17+
918
function getClient() {
1019
if (!client) {
1120
client = new PostHog(POSTHOG_API_KEY, { host: POSTHOG_HOST, flushAt: 1, flushInterval: 0 });
@@ -20,11 +29,13 @@ function getDistinctId() {
2029

2130
/**
2231
* Track an analytics event. Fire-and-forget — never throws or blocks the CLI.
32+
* Respects telemetry opt-out via config or CODEANT_TELEMETRY_DISABLED env var.
2333
* @param {string} event - Event name (e.g. 'review_triggered')
2434
* @param {Object} [properties={}] - Event properties
2535
*/
2636
export function track(event, properties = {}) {
2737
try {
38+
if (isTelemetryDisabled()) return;
2839
getClient().capture({
2940
distinctId: getDistinctId(),
3041
event,

0 commit comments

Comments
 (0)