Fathom Lite Documentation

repository·master·Indexed 27 days ago

https://github.com/usefathom/fathom

An open-source, self-hosted website analytics solution. Fathom Lite is a lightweight version of the hosted Fathom Analytics service that supports Postgres, MySQL, and SQLite databases. It provides a CLI for user management, Docker and Docker Compose deployment options, and a privacy-focused tracking system that respects Do Not Track (DNT) settings and avoids collecting personally identifiable information (PII).

Tokens
6.4K
Snippets
24
Records
46
Agent score
93%

What's inside Fathom Lite

  1. Understand Fathom data tracking and privacy

    master

    Fathom is designed to track no personally identifiable information (PII).

    Tracking Logic:

    • Unique Visitors: Visitors are assigned a random string to identify unique pageviews.
    • Session Processing: If a visitor moves to another page, the previous pageview is processed and deleted within 1 minute. If the visitor leaves the site, the pageview is processed and deleted when the session ends (after 30 minutes).
    • Do Not Track (DNT): Fathom respects the navigator.doNotTrack setting in user browsers. If DNT is enabled, Fathom will not track that visitor.
  2. Run Fathom as a Systemd service

    master

    To run Fathom as a background service that automatically restarts on server reboots (on Ubuntu 16.04 or later), create a service configuration file at /etc/systemd/system/fathom.service. Ensure the fathom binary is installed and available in your $PATH.

    [Unit]
    Description=Starts the fathom server
    Requires=network.target
    After=network.target
    
    [Service]
    Type=simple
    User=$USER
    Restart=always
    RestartSec=6
    WorkingDirectory=/etc/fathom # (or where fathom should store its files)
    ExecStart=fathom server
    
    [Install]
    WantedBy=multi-user.target
  3. Configure NGINX with HTTPS using Let's Encrypt

    master

    To protect your Fathom instance with HTTPS using Let's Encrypt, follow these steps:

    1. Generate a certificate using the Certbot webroot plugin: certbot certonly --webroot --webroot-path /var/www/yourfathom.com -d yourfathom.com

    2. Update your /etc/nginx/sites-enabled/yourfathom.com file to include the SSL configuration and the .well-known location block. The alias directive must point to the directory used in the --webroot-path command.

    server {
    	listen 443 ssl http2;
    	listen [::]:443 ssl http2;
    
    	server_name yourfathom.com;
    
    	ssl_certificate /path/to/your/fullchain.pem;
    	ssl_certificate_key /path/to/your/privkey.pem;
    
    	location /.well-known {
    		alias /var/www/yourfathom.com/.well-known;
    	}
    
    	location / {
    		proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header X-Forwarded-For $remote_addr;
    		proxy_set_header Host $host;
    		proxy_pass http://127.0.0.1:9000; 
    	}
    }
  4. Use NGINX as a reverse proxy for Fathom

    master

    It is recommended to use NGINX to handle multiple sites and SSL certificates. Create an NGINX configuration file (e.g., in /etc/nginx/sites-enabled/) to proxy requests to the Fathom server running on 127.0.0.1:9000.

    After creating the configuration, test and reload NGINX.

    # Create config in /etc/nginx/sites-enabled/my-fathom-site
    server {
    	server_name my-fathom-site.com;
    
    	location / {
    		proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header X-Forwarded-For $remote_addr;
    		proxy_set_header Host $host;
    		proxy_pass http://127.0.0.1:9000; 
    	}
    }
    
    # Test and reload
    nginx -t
    service nginx reload
  5. Set up Fathom Lite for development

    master

    To run a development version of Fathom Lite, ensure you have Go and NPM installed, then follow these steps:

    1. Clone the repository into your GOPATH: git clone https://github.com/usefathom/fathom.git $GOPATH/src/github.com/usefathom/fathom
    2. Compile the project: make build
    3. (Optional) Configure custom values as per the configuration documentation.
    4. (Required) Create an initial user account using the CLI.
    5. Start the webserver and access the dashboard at http://localhost:8080.
    git clone https://github.com/usefathom/fathom.git $GOPATH/src/github.com/usefathom/fathom
    make build
    ./fathom user add --email=<email> --password=<password>
    ./fathom server
  6. Configure Fathom to start automatically on boot with Systemd

    master

    To ensure the Fathom server restarts automatically on system reboot, create a Systemd service file at /etc/systemd/system/my-fathom-site.service.

    Ensure you replace $USER with your actual username and set the WorkingDirectory to the directory containing your .env file.

    After creating the file, reload the daemon, enable the service, and start it.

    # Create /etc/systemd/system/my-fathom-site.service
    [Unit]
    Description=Starts the fathom server
    Requires=network.target
    After=network.target
    
    [Service]
    Type=simple
    User=$USER
    Restart=always
    RestartSec=3
    WorkingDirectory=/home/$USER/my-fathom-site
    ExecStart=/usr/local/bin/fathom server
    
    [Install]
    WantedBy=multi-user.target
    
    # Apply changes
    systemctl daemon-reload
    systemctl enable my-fathom-site
    systemctl start my-fathom-site
  7. Use FATHOM_DATABASE_URL for database connection

    master

    Instead of individual database settings, you can use FATHOM_DATABASE_URL to provide a single connection string.

    When using specific drivers, ensure you include the following parameters in your DSN:

    • MySQL: Include ?parseTime=true&loc=Local.
    • SQLite: Include ?_loc=auto.

    Example for MySQL:

    FATHOM_DATABASE_DRIVER=mysql
    FATHOM_DATABASE_URL=root:@tcp/fathom1?loc=Local&parseTime=true
  8. Configure and manage the Fathom Systemd service

    master

    After creating your /etc/systemd/system/fathom.service file, follow these steps to manage the service:

    1. Reload systemd: Run sudo systemctl daemon-reload to load the new configuration.
    2. Enable at boot: Run sudo systemctl enable fathom to ensure the service starts automatically when the system boots.
    3. Disable at boot: Run sudo systemctl disable fathom to prevent the service from starting automatically at boot.
    4. Manual control:
      • Start: sudo systemctl start fathom
      • Stop: sudo systemctl stop fathom
    sudo systemctl daemon-reload
    sudo systemctl enable fathom
    sudo systemctl start fathom
    sudo systemctl stop fathom
    sudo systemctl disable fathom
  9. Restart the Fathom web server

    master

    After updating the Fathom binary, you must restart the running web server process for changes to take effect.

    If using Systemd (standard installation): Use systemctl to restart your specific Fathom service: systemctl restart <your-fathom-service>

    Manual method: Alternatively, you can stop the server by killing all running Fathom processes: pkill fathom

    systemctl restart my-fathom-site
    # OR
    pkill fathom