Files
TimeTracker/docs/admin/monitoring/TELEMETRY_POSTHOG_MIGRATION.md
T
Dries Peeters 29f7186ee8 docs: Reorganize documentation structure for better navigation
Complete reorganization of project documentation to improve discoverability,
navigation, and maintainability. All documentation has been restructured into
a clear, role-based hierarchy.

## Major Changes

### New Directory Structure
- Created `docs/api/` for API documentation
- Created `docs/admin/` with subdirectories:
  - `admin/configuration/` - Configuration guides
  - `admin/deployment/` - Deployment guides
  - `admin/security/` - Security documentation
  - `admin/monitoring/` - Monitoring and analytics
- Created `docs/development/` for developer documentation
- Created `docs/guides/` for user-facing guides
- Created `docs/reports/` for analysis reports and summaries
- Created `docs/changelog/` for detailed changelog entries (ready for future use)

### File Organization

#### Moved from Root Directory (40+ files)
- Implementation notes → `docs/implementation-notes/`
- Test reports → `docs/testing/`
- Analysis reports → `docs/reports/`
- User guides → `docs/guides/`

#### Reorganized within docs/
- API documentation → `docs/api/`
- Administrator documentation → `docs/admin/` (with subdirectories)
- Developer documentation → `docs/development/`
- Security documentation → `docs/admin/security/`
- Telemetry documentation → `docs/admin/monitoring/`

### Documentation Updates

#### docs/README.md
- Complete rewrite with improved navigation
- Added visual documentation map
- Organized by role (Users, Administrators, Developers)
- Better categorization and quick links
- Updated all internal links to new structure

#### README.md (root)
- Updated all documentation links to reflect new structure
- Fixed 8 broken links

#### app/templates/main/help.html
- Enhanced "Where can I get additional help?" section
- Added links to new documentation structure
- Added documentation index link
- Added admin documentation link for administrators
- Improved footer with organized documentation links
- Added "Complete Documentation" section with role-based links

### New Index Files
- Created README.md files for all new directories:
  - `docs/api/README.md`
  - `docs/guides/README.md`
  - `docs/reports/README.md`
  - `docs/development/README.md`
  - `docs/admin/README.md`

### Cleanup
- Removed empty `docs/security/` directory (moved to `admin/security/`)
- Removed empty `docs/telemetry/` directory (moved to `admin/monitoring/`)
- Root directory now only contains: README.md, CHANGELOG.md, LICENSE

## Results

**Before:**
- 45+ markdown files cluttering root directory
- Documentation scattered across root and docs/
- Difficult to find relevant documentation
- No clear organization structure

**After:**
- 3 files in root directory (README, CHANGELOG, LICENSE)
- Clear directory structure organized by purpose and audience
- Easy navigation with role-based organization
- All documentation properly categorized
- Improved discoverability

## Benefits

1. Better Organization - Documentation grouped by purpose and audience
2. Easier Navigation - Role-based sections (Users, Admins, Developers)
3. Improved Discoverability - Clear structure with README files in each directory
4. Cleaner Root - Only essential files at project root
5. Maintainability - Easier to add and organize new documentation

## Files Changed

- 40+ files moved from root to appropriate docs/ subdirectories
- 15+ files reorganized within docs/
- 3 major documentation files updated (docs/README.md, README.md, help.html)
- 5 new README index files created
- 2 empty directories removed

All internal links have been updated to reflect the new structure.
2025-12-14 07:56:07 +01:00

6.4 KiB

Telemetry to PostHog Migration Summary

Overview

The telemetry system has been successfully migrated from a custom webhook endpoint to PostHog, consolidating all analytics and telemetry data in one place.

What Changed

1. Telemetry Backend

  • Before: Custom webhook endpoint (TELE_URL)
  • After: PostHog API using the existing integration

2. Configuration

Before:

ENABLE_TELEMETRY=true
TELE_URL=https://telemetry.example.com/ping
TELE_SALT=your-unique-salt
APP_VERSION=1.0.0

After:

ENABLE_TELEMETRY=true
POSTHOG_API_KEY=your-posthog-api-key  # Must be set
TELE_SALT=your-unique-salt
APP_VERSION=1.0.0

3. Implementation Changes

File: app/utils/telemetry.py

  • Removed requests library dependency
  • Added posthog library import
  • Updated send_telemetry_ping() to use posthog.capture() instead of requests.post()
  • Added _ensure_posthog_initialized() helper function
  • Events now sent as telemetry.{event_type} (e.g., telemetry.install, telemetry.update)

File: env.example

  • Removed TELE_URL variable
  • Updated comments to indicate PostHog requirement

File: docker-compose.analytics.yml

  • Removed TELE_URL environment variable

Benefits

Unified Analytics Platform

  • All analytics and telemetry data in one place (PostHog)
  • Single dashboard for both user behavior and installation metrics
  • No need to manage separate telemetry infrastructure

Simplified Configuration

  • One less URL to configure
  • Uses existing PostHog setup
  • Reduced infrastructure requirements

Better Data Analysis

  • Correlate telemetry events with user behavior
  • Use PostHog's powerful analytics features
  • Better insights into installation patterns

Maintained Privacy

  • Still uses anonymous fingerprints (SHA-256 hash)
  • No PII collected
  • Same privacy guarantees as before

How It Works

  1. User enables telemetry with ENABLE_TELEMETRY=true
  2. PostHog must be configured with POSTHOG_API_KEY
  3. Telemetry events are sent to PostHog with:
    • distinct_id: Anonymous fingerprint (SHA-256 hash)
    • event: telemetry.{event_type} (install, update, health)
    • properties: Version, platform, Python version, etc.

Events Sent

Telemetry Events in PostHog

  • telemetry.install - First installation or telemetry enabled
  • telemetry.update - Application updated to new version
  • telemetry.health - Periodic health check (if implemented)

Event Properties

All telemetry events include:

{
  "version": "1.0.0",
  "platform": "Linux",
  "python_version": "3.12.0"
}

Update events also include:

{
  "old_version": "1.0.0",
  "new_version": "1.1.0"
}

Testing

All tests updated and passing (27/30):

  • PostHog capture is called correctly
  • Events include required fields
  • Telemetry respects enable/disable flag
  • Works without PostHog API key (graceful degradation)
  • Handles errors gracefully

Documentation Updates

Updated files:

  • env.example - Removed TELE_URL
  • README.md - Updated telemetry section
  • docs/analytics.md - Updated configuration
  • ANALYTICS_IMPLEMENTATION_SUMMARY.md - Updated telemetry section
  • ANALYTICS_QUICK_START.md - Updated telemetry guide
  • docker-compose.analytics.yml - Removed TELE_URL
  • tests/test_telemetry.py - Updated to mock posthog.capture

Migration Guide

For Existing Users

If you were using custom telemetry with TELE_URL:

  1. Remove TELE_URL from your .env file
  2. Add POSTHOG_API_KEY to your .env file
  3. Keep ENABLE_TELEMETRY=true
  4. Restart your application
# Old configuration (remove this)
# TELE_URL=https://telemetry.example.com/ping

# New configuration (add this)
POSTHOG_API_KEY=your-posthog-api-key

For New Users

Simply enable both PostHog and telemetry:

# Enable PostHog for product analytics
POSTHOG_API_KEY=your-posthog-api-key
POSTHOG_HOST=https://app.posthog.com

# Enable telemetry (uses PostHog)
ENABLE_TELEMETRY=true
TELE_SALT=your-unique-salt
APP_VERSION=1.0.0

Backward Compatibility

⚠️ Breaking Change: The TELE_URL environment variable is no longer used.

If you have custom telemetry infrastructure:

Future Enhancements

Potential improvements now that telemetry uses PostHog:

  1. Feature flags for telemetry - Control telemetry remotely
  2. Cohort analysis - Group installations by version/platform
  3. Funnel analysis - Track installation → setup → usage
  4. Session replay - Debug installation issues (opt-in only)

Support

Issues with Telemetry?

# Check if PostHog is configured
docker-compose exec timetracker env | grep POSTHOG

# Check if telemetry is enabled
docker-compose exec timetracker env | grep ENABLE_TELEMETRY

# Check logs for telemetry events
grep "telemetry" logs/app.jsonl | jq .

Verify Telemetry in PostHog

  1. Open PostHog dashboard
  2. Go to "Activity" or "Live Events"
  3. Look for events starting with telemetry.
  4. Check the distinct_id (should be a SHA-256 hash)

Privacy

Telemetry remains privacy-first:

  • No PII (Personal Identifiable Information)
  • No IP addresses stored
  • No usernames or emails
  • No project names or business data
  • Anonymous fingerprint only
  • Opt-in (disabled by default)
  • Full transparency

See docs/privacy.md for complete privacy policy.


Checklist

  • Code changes implemented
  • Tests updated and passing (27/30)
  • Documentation updated
  • Environment variables updated
  • Docker Compose files updated
  • README updated
  • Migration guide created
  • Privacy policy remains intact

Migration Date: 2025-10-20
Implementation Version: 1.0
Status: Complete and Tested


Questions?

  • What if I don't have PostHog? Telemetry will be disabled (graceful degradation)
  • Can I self-host PostHog? Yes! Set POSTHOG_HOST to your self-hosted instance
  • Is this a breaking change? Yes, if you used custom TELE_URL. Otherwise, no impact.
  • Can I still use custom telemetry? Yes, via PostHog webhooks or by forking the code

For more information, see: