Implements privacy-first telemetry tracking using PostHog for SonicJS installations and usage metrics. This addresses issue #304. ## Features ### Core Telemetry Service - Privacy-first telemetry service with PostHog integration - Anonymous installation ID generation (UUID v4) - Event queuing and batching for efficient tracking - Silent failures - telemetry never blocks the application - Proper shutdown and cleanup mechanisms ### Privacy & Security - No PII collection (no emails, usernames, IPs, file paths) - Anonymous UUIDs stored in ~/.sonicjs/telemetry.json - Data sanitization for error messages and routes - Multiple opt-out mechanisms: - SONICJS_TELEMETRY=false - DO_NOT_TRACK=1 - Transparent telemetry notice in CLI ### CLI Integration - Installation event tracking in create-sonicjs: - installation_started - installation_completed - installation_failed - installation_cancelled - Privacy notice display during installation - OS, Node version, and package manager tracking ### Testing - 35 comprehensive tests across 2 test suites - Tests for telemetry service functionality - Tests for utility functions (ID generation, sanitization) - All tests passing ### Documentation - Complete telemetry documentation (docs/telemetry.md) - Privacy policy and data collection transparency - Opt-out instructions - Technical implementation details - FAQ section ## Technical Details **PostHog Configuration:** - API Key: phc_VuhFUIJLXzwyGjlgQ67dbNeSh5x4cp9F8i15hZFIDhs - Host: https://us.i.posthog.com - Batch Size: 20 events (runtime), 1 event (CLI) - Flush Interval: 10s (runtime), 1s (CLI) **Files Added:** - packages/core/src/services/telemetry-service.ts - packages/core/src/services/telemetry-service.test.ts - packages/core/src/types/telemetry.ts - packages/core/src/utils/telemetry-id.ts - packages/core/src/utils/telemetry-id.test.ts - packages/core/src/utils/telemetry-config.ts - packages/create-app/src/telemetry.js - packages/create-app/src/telemetry-notice.js - docs/telemetry.md **Dependencies Added:** - posthog-node ^4.0.0 (to @sonicjs-cms/core and create-sonicjs) ## Future Phases This implements Phase 1 (Foundation). Future phases will add: - Phase 2: Runtime telemetry (dev server events, plugin tracking) - Phase 3: Admin UI analytics (page views, feature usage) - Phase 4: Advanced features (feature flags, A/B testing) Closes #304 ๐ค Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6.9 KiB
SonicJS Telemetry
Overview
SonicJS collects anonymous, privacy-respecting telemetry data to help us understand how the framework is being used and identify areas for improvement. We are committed to transparency and user privacy.
What We Collect
Installation Metrics
- Installation success/failure rates
- Installation duration
- Template selection
- Operating system (macOS, Linux, Windows)
- Node.js version (major.minor only)
- Package manager (npm, yarn, pnpm, bun)
Runtime Metrics (Future)
- Development server start/stop events
- Plugin activation counts (no plugin names)
- Collection/content creation counts (no actual data)
- Generic feature usage patterns
Admin UI Analytics (Future)
- Page views (route patterns only, sanitized)
- Error types (sanitized, no sensitive data)
What We DON'T Collect
We are committed to NEVER collecting personally identifiable information (PII):
- โ Email addresses
- โ Usernames or passwords
- โ IP addresses
- โ File paths with usernames
- โ Content or data you create
- โ API keys or secrets
- โ Project names or identifiers
- โ Any other PII
All data is anonymized using:
- Random UUIDs for installation identification
- Sanitized error messages (type only)
- Sanitized routes (patterns only)
- Hash-based project identification
How It Works
Installation ID
- A random UUID is generated and stored in
~/.sonicjs/telemetry.json - This ID is used to track installations anonymously
- The ID persists across sessions but is unique per user
- You can delete this file at any time
Data Collection
- Events are tracked using PostHog (privacy-first analytics platform)
- Events are batched and sent asynchronously
- Telemetry never blocks or slows down your application
- Silent failures - telemetry errors never crash your app
Data Storage
- Data is stored on PostHog's secure servers
- We use PostHog Cloud (free tier) initially
- Option to self-host if needed in the future
- Data retention: 1 year
Opting Out
We respect your choice to disable telemetry. You can opt out in multiple ways:
1. Environment Variable (Recommended)
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
export SONICJS_TELEMETRY=false
2. DO_NOT_TRACK Standard
# SonicJS respects the DO_NOT_TRACK standard
export DO_NOT_TRACK=1
3. CLI Flag (Future)
# During installation
npx create-sonicjs my-app --no-telemetry
4. Configuration File (Future)
// sonicjs.config.js
export default {
telemetry: false
}
Verify Telemetry Status
# Check if telemetry is enabled
echo $SONICJS_TELEMETRY
# Remove telemetry ID
rm ~/.sonicjs/telemetry.json
Why Telemetry?
Telemetry helps us:
- Improve Reliability: Identify and fix installation failures
- Guide Development: Understand which features are most used
- Support Users Better: See common error patterns
- Measure Adoption: Track SonicJS growth and engagement
- Optimize Performance: Identify bottlenecks in workflows
Privacy Policy
Data Usage
- Data is used only for product improvement
- Data is never sold or shared with third parties
- Data is never used for marketing or advertising
- Data is aggregated and anonymized for analysis
Data Access
- Only core SonicJS maintainers have access
- Access is logged and audited
- Data is never exported to external systems
Data Deletion
- You can request data deletion at any time
- Email us at privacy@sonicjs.com
- We will delete your installation ID's data within 30 days
Technical Details
PostHog Integration
- SDK:
posthog-nodev4+ - Endpoint:
https://us.i.posthog.com(PostHog Cloud US) - Project: SonicJS Production
- Batch Size: 20 events (runtime), 1 event (CLI)
- Flush Interval: 10 seconds (runtime), 1 second (CLI)
- Timeout: 5 seconds
Event Schema
{
event: 'installation_started',
properties: {
timestamp: '2025-11-14T10:00:00.000Z',
version: '2.0.0',
os: 'darwin',
nodeVersion: '18.0',
packageManager: 'npm',
template: 'starter'
},
distinctId: 'uuid-v4-installation-id'
}
Sanitization
All data passes through sanitization functions:
// Route sanitization
'/admin/users/123' โ '/admin/users/:id'
'/admin/users/550e8400-...' โ '/admin/users/:id'
// Error sanitization
'TypeError: Cannot read property X' โ 'TypeError'
'/Users/john/project/file.js' โ '/Users/***/project/file.js'
'user@example.com' โ '***@***.***'
Implementation Status
Phase 1: Foundation โ (Current)
- Telemetry service module
- Anonymous installation ID generation
- Opt-out mechanism
- Installation event tracking
- CLI integration with notice
Phase 2: Runtime Telemetry ๐ง (Future)
- Dev server events
- Plugin activation tracking
- Collection/content creation events
Phase 3: Admin UI Analytics ๐ (Future)
- Page view tracking
- Feature usage tracking
- Error tracking
Phase 4: Advanced Features ๐ (Future)
- Feature flags integration
- A/B testing framework
- Progressive rollouts
Cost & Scaling
PostHog Free Tier
- 1M events/month - FREE
- Unlimited users
- 1 year retention
- 100% features
Estimated Usage
- Small (1K installs/month): ~6K events/month
- Medium (10K installs/month): ~60K events/month
- Large (100K installs/month): ~600K events/month
Mitigation if Exceeding Free Tier
- Sampling: Track 50% of events
- Self-hosting: Use PostHog open source
- Custom solution: Build lightweight alternative
FAQ
Is telemetry enabled by default?
Yes, but you can easily opt out using environment variables.
Can I see what data is being sent?
Yes, set DEBUG=true to see all telemetry events in the console.
What if I don't trust PostHog?
We respect that. You can disable telemetry or wait for self-hosting support.
Does telemetry slow down my app?
No. Events are batched, sent asynchronously, and never block execution.
Can I opt back in after opting out?
Yes, simply remove the SONICJS_TELEMETRY=false environment variable.
How do I delete my data?
Email privacy@sonicjs.com with your installation ID (found in ~/.sonicjs/telemetry.json).
Open Source Commitment
The telemetry implementation is 100% open source:
- Code:
packages/core/src/services/telemetry-service.ts - Tests:
packages/core/src/services/telemetry-service.test.ts - Documentation: This file
You can inspect, audit, and contribute to the telemetry code at any time.
Feedback
We welcome feedback on our telemetry implementation:
- GitHub Issues: https://github.com/lane711/sonicjs/issues
- Email: privacy@sonicjs.com
- Discord: Join our community
Updates
This document will be updated as we roll out new telemetry features. Check the changelog for updates.
Last Updated: November 14, 2025 Version: 2.0.0