#!/bin/bash # Setup script for local development with analytics set -e echo "🔧 TimeTracker Development Analytics Setup" echo "" # Check if .gitignore already has the entry if ! grep -q "analytics_defaults_local.py" .gitignore 2>/dev/null; then echo "app/config/analytics_defaults_local.py" >> .gitignore echo "✅ Added analytics_defaults_local.py to .gitignore" fi # Check if local config already exists if [ -f "app/config/analytics_defaults_local.py" ]; then echo "⚠️ Local config already exists" read -p "Overwrite? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Keeping existing config" exit 0 fi fi # Prompt for keys echo "" echo "📝 Enter your development analytics keys:" echo "(Leave empty to skip)" echo "" read -p "PostHog API Key (starts with phc_): " POSTHOG_KEY read -p "PostHog Host [https://app.posthog.com]: " POSTHOG_HOST POSTHOG_HOST=${POSTHOG_HOST:-https://app.posthog.com} read -p "Sentry DSN (optional): " SENTRY_DSN read -p "Sentry Traces Rate [1.0]: " SENTRY_RATE SENTRY_RATE=${SENTRY_RATE:-1.0} # Create local config file cat > app/config/analytics_defaults_local.py </dev/null; then echo "" echo "📝 Updating app/config/__init__.py..." # Backup original cp app/config/__init__.py app/config/__init__.py.backup # Create new version with local import cat > app/config/__init__.py <<'EOF' """ Configuration module for TimeTracker. This module contains analytics configuration that is embedded at build time to enable consistent telemetry collection across all installations. For local development, it tries to import from analytics_defaults_local.py first. """ # Try to import local development config first, fallback to production config try: from app.config.analytics_defaults_local import get_analytics_config, has_analytics_configured print("📊 Using local analytics configuration for development") except ImportError: from app.config.analytics_defaults import get_analytics_config, has_analytics_configured __all__ = ['get_analytics_config', 'has_analytics_configured'] EOF echo "✅ Updated app/config/__init__.py to use local config" echo " (Backup saved as __init__.py.backup)" fi echo "" echo "🎉 Setup complete!" echo "" echo "Next steps:" echo "1. Start the application: docker-compose up -d" echo "2. Access: http://localhost:5000" echo "3. Complete setup and enable telemetry" echo "4. Check PostHog dashboard for events" echo "" echo "⚠️ Remember:" echo "- This config is gitignored and won't be committed" echo "- Use a separate PostHog project for development" echo "- Before committing, ensure no keys in analytics_defaults.py" echo "" echo "To revert changes:" echo " rm app/config/analytics_defaults_local.py" echo " mv app/config/__init__.py.backup app/config/__init__.py" echo ""