Umami Analytics

repository·master·Indexed 12 days ago

https://github.com/umami-software/umami

A modern, privacy-focused, self-hosted analytics platform that tracks website traffic, campaigns, behavior, and conversions without using cookies or tracking users. Version 3.3.0 supports deployment via Docker, Podman, or from source using Node.js 18.18+ and PostgreSQL v12.14+.

Tokens
7.5K
Snippets
23
Records
30
Agent score
98%

What's inside Umami

  1. Install Umami with Docker

    master

    You can deploy Umami using Docker images or Docker Compose.

    Using Docker Image

    Pull the latest image from the Umami registry:

    docker pull docker.umami.is/umami-software/umami:latest

    Using Docker Compose

    To run Umami along with a managed PostgreSQL database, use the provided compose file:

    docker compose up -d
  2. Deploy Umami using Podman Compose

    master

    To deploy Umami using Podman, follow these steps:

    1. Prepare the environment file: Rename env.sample to .env.
    2. Configure credentials: Edit the .env file and ensure you set the required passwords at a minimum.
    3. Launch the application: Run podman-compose up -d to start Umami in detached mode.

    To stop the application, run: podman-compose down

    # Prepare and configure
    cp env.sample .env
    # (Edit .env with your passwords)
    
    # Start Umami
    podman-compose up -d
    
    # Stop Umami
    podman-compose down
  3. Install Umami as a systemd user service

    master

    You can run Umami as a systemd service for automatic management.

    1. Configure the service file: Edit umami.service and update the following variables to match your deployment paths:

      • WorkingDirectory: The absolute path to the directory containing your podman-compose.yml.
      • EnvironmentFile: The absolute path to your .env file.
    2. Install the service: Run the provided installation script. Note that this script enables and starts the service, so you should stop any currently running Umami instances before running it.

    Important: If Umami is already running, stop it first using podman-compose down before running the installation script.

    # 1. Edit umami.service
    # WorkingDirectory=/your/path/to/podman-compose
    # EnvironmentFile=/your/path/to/.env
    
    # 2. Stop existing instance if running
    podman-compose down
    
    # 3. Install and start service
    ./install-systemd-user-service
  4. Update Umami

    master

    To update your Umami installation, follow the steps corresponding to your deployment method.

    Updating from Source

    Pull the latest code, reinstall dependencies, and rebuild:

    git pull
    pnpm install
    pnpm build

    Updating Docker Compose

    Pull the latest images and recreate the containers:

    docker compose pull
    docker compose up --force-recreate -d
  5. Install Umami from source

    master

    To install Umami from source, ensure your environment meets the requirements, clone the repository, install dependencies, configure the environment, build, and start the application.

    Requirements

    • Node.js: version 18.18+
    • PostgreSQL: version v12.14+

    Installation Steps

    1. Clone and Install Dependencies:
      git clone https://github.com/umami-software/umami.git
      cd umami
      pnpm install
    2. Configure Environment: Create an .env file in the root directory and provide the DATABASE_URL.
    3. Build the Application:
      pnpm run build
      Note: The build step automatically creates database tables and an initial admin user (username: admin, password: umami) if it is a fresh installation.
    4. Start the Application:
      pnpm run start
      The application defaults to http://localhost:3000.
    git clone https://github.com/umami-software/umami.git
    cd umami
    pnpm install
    pnpm run build
    pnpm run start
  6. How session recording and heatmaps work in Umami

    master

    Umami provides two types of user behavior tracking through its recorder script:

    1. Session Replay: Uses rrweb to capture DOM mutations and reconstruct the user's session. It buffers events and flushes them to /api/record periodically or when the buffer reaches a size limit (REPLAY_MAX_PAYLOAD_SIZE). If a single event (like a full snapshot) is too large, it is split into fragments of type umami:rrweb-event-fragment.
    2. Heatmaps: Captures user interactions like click and scroll. It tracks viewport dimensions, page dimensions, and scroll percentages. Heatmap events are buffered and flushed to /api/record (with type: 'heatmap') either when the buffer reaches HEATMAP_FLUSH_EVENT_COUNT (20) or after a HEATMAP_FLUSH_INTERVAL (5000ms).

    Both features are subject to a sampleRate (default 0.15) to reduce overhead and data volume.

  7. Configure recording privacy with maskLevel

    master

    The recorder supports different levels of data masking to protect user privacy. This is configured via the maskLevel setting received from the Umami API.

    • moderate (default): Masks all input elements (maskAllInputs: true).
    • strict: Masks all input elements and all text content using the maskTextSelector: '*' selector.

    Masking is applied during the rrweb recording process to ensure sensitive information is not captured in the DOM snapshots.

  8. Structure event data using `EventData`

    master

    When sending custom data with events, use the EventData interface. To maintain performance, Umami enforces the following constraints on data:

    • Numbers: Maximum precision of 4.
    • Strings: Maximum length of 500 characters.
    • Arrays: Converted to a string with a maximum length of 500.
    • Objects: Maximum of 50 properties (arrays are treated as a single property).

    EventDataValue can be a boolean, number, string, null, EventData, or an array of these types.

    const myData: EventData = {
      name: 'newsletter',
      id: 123,
      is_active: true
    };
    
    umami.track('signup', myData);
  9. Configure Umami environment variables

    master

    Umami uses environment variables for configuration. At a minimum, you must provide a PostgreSQL connection string.

    Required Variables

    • DATABASE_URL: The connection string for your PostgreSQL database. Format: postgresql://username:mypassword@localhost:5432/mydb

    Optional Variables

    • API_URL: Sets the base URL used by internal UI API calls.
      • Use a relative path for BASE_PATH (e.g., API_URL=/internal-api).
      • Use an absolute URL to proxy through the local /api route (e.g., API_URL=https://api.example.com/api).
    DATABASE_URL=postgresql://username:mypassword@localhost:5432/mydb
    API_URL=/internal-api
  10. Deploy Umami using Docker Compose

    master

    You can deploy Umami using the provided docker-compose.yml file. This setup includes the Umami application service and a PostgreSQL database service. The application is accessible on port 3000 by default.

    services:
      umami:
        image: ghcr.io/umami-software/umami:latest
        ports:
          - "3000:3000"
        environment:
          DATABASE_URL: postgresql://umami:umami@db:5432/umami
          APP_SECRET: replace-me-with-a-random-string
        depends_on:
          db:
            condition: service_healthy
        init: true
        restart: always
        healthcheck:
          test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"]
          interval: 5s
          timeout: 5s
          retries: 5
      db:
        image: postgres:15-alpine
        environment:
          POSTGRES_DB: umami
          POSTGRES_USER: umami
          POSTGRES_PASSWORD: umami
        volumes:
          - umami-db-data:/var/lib/postgresql/data
        restart: always
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
          interval: 5s
          timeout: 5s
          retries: 5
    volumes:
      umami-db-data:
  11. Configure the Umami Recorder via script attributes

    master

    The Umami recorder is initialized via a <script> tag. It automatically reads configuration from data- attributes on the script element itself. To ensure the recorder functions correctly, the following attributes must be present:

    • data-website-id: The unique ID of the website being tracked.
    • data-host-url: (Optional) The base URL of your Umami instance. If omitted, it defaults to the directory of the current script or __COLLECT_API_HOST__.

    When the script loads, it fetches configuration from ${hostBase}/api/websites/${website}/recorder to determine if recording is enabled and to set parameters like sampleRate, maskLevel, and maxDuration.

    <!-- Example of how the script should be included in your HTML -->
    <script
      src="https://your-umami-instance.com/recorder.js"
      data-website-id="YOUR_WEBSITE_ID"
      data-host-url="https://your-umami-instance.com"
    ></script>
  12. Configure PostgreSQL environment variables

    master

    The db service uses standard PostgreSQL environment variables to initialize the database:

    • POSTGRES_DB: The name of the database to create (default: umami).
    • POSTGRES_USER: The superuser username (default: umami).
    • POSTGRES_PASSWORD: The password for the superuser (default: umami).