### Run Rybbit Setup Script Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx This command executes the primary setup script for Rybbit. It requires your domain name as an argument and will configure environment variables and start the application using Docker Compose. ```bash ./setup.sh your.domain.name ``` -------------------------------- ### Update Rybbit Installation Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx To update Rybbit to the latest version, first pull the new code from the repository and then run the update script to rebuild containers. ```bash git pull ./update.sh ``` -------------------------------- ### Start Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx Use this script to start all of Rybbit's services after they have been stopped. ```bash ./start.sh ``` -------------------------------- ### Start Rybbit with Built-in Caddy (Automatic SSL) Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Starts all Rybbit services using Docker Compose, including Caddy for automatic SSL certificate management. This is the simplest setup if no reverse proxy is pre-existing. ```bash docker compose up -d ``` -------------------------------- ### Start Rybbit Services with Docker Compose Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-manual.mdx Commands to start all Rybbit services using Docker Compose in detached mode. It also provides an alternative command to start specific services if Caddy is not being used. ```bash # Start all services docker compose up -d # Or start specific services (without Caddy) docker compose up -d backend client clickhouse postgres ``` -------------------------------- ### Restart Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx This command restarts all the services managed by Rybbit. ```bash ./restart.sh ``` -------------------------------- ### Clone Rybbit Repository and Navigate Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx This snippet demonstrates how to clone the Rybbit project from GitHub using Git and then change the directory into the newly cloned repository. ```bash git clone https://github.com/rybbit-io/rybbit.git cd rybbit ``` -------------------------------- ### Rybbit Setup Script Command-Line Options Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-advanced.mdx The Rybbit setup script accepts a domain name and several optional flags to customize the installation. These options control features like the built-in webserver and port mappings for backend and client services. ```bash ./setup.sh [options] Available options: - --no-webserver: Disable the built-in Caddy webserver - --backend-port : Set custom host port for backend (default: 3001) - --client-port : Set custom host port for client (default: 3002) - --help: Show help message Examples: # Custom ports with built-in webserver ./setup.sh tracking.example.com --backend-port 8080 --client-port 8081 # Custom ports with your own webserver ./setup.sh tracking.example.com --no-webserver --backend-port 8080 --client-port 8081 ``` -------------------------------- ### Starting Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/nginx-proxy-manager.mdx Command to start all defined Rybbit services in detached mode (-d). After starting, use `docker compose ps` to verify that all services are running correctly. ```bash docker compose up -d # Verify all services are running docker compose ps ``` -------------------------------- ### Run Development Server (npm, pnpm, yarn) Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/README.md Commands to start the Next.js development server using different package managers. Ensure you have the necessary dependencies installed. ```bash npm run dev # or pnpm dev # or yarn dev ``` -------------------------------- ### Initial Setup on VPS for Rybbit Monitor Agent Source: https://github.com/rybbit-io/rybbit/blob/master/monitor-agent/DEPLOYMENT.md This snippet covers the initial steps to set up the Rybbit Monitor Agent on a VPS, including creating directories, setting environment variables, and configuring the agent's port, host, region, allowed IPs, domain name, and log level. ```bash # SSH into your VPS ssh user@your-vps-ip # Create directory for the agent sudo mkdir -p /opt/rybbit-monitor-agent cd /opt/rybbit-monitor-agent # Create environment file sudo nano .env ``` ```env PORT=3003 HOST=0.0.0.0 REGION=us-east # Change based on region ALLOWED_IPS=1.2.3.4,5.6.7.8 # IP addresses of your main server DOMAIN_NAME=your-monitor-domain.com # Domain for this monitor agent LOG_LEVEL=info ``` -------------------------------- ### Systemd Service Setup for Rybbit Monitor Agent Source: https://github.com/rybbit-io/rybbit/blob/master/monitor-agent/DEPLOYMENT.md This snippet outlines the process for setting up the Rybbit Monitor Agent as a Systemd service on a VPS, typically for non-Docker deployments. It involves copying systemd files, running a setup script, configuring the environment, and restarting the service. ```bash # Copy the systemd files to your VPS scp -r systemd/ user@your-vps:/tmp/ # SSH into the VPS ssh user@your-vps # Run the setup script cd /tmp/systemd sudo ./setup.sh # Configure the environment sudo nano /opt/rybbit-monitor-agent/.env # Restart the service sudo systemctl restart rybbit-monitor-agent ``` -------------------------------- ### Make Scripts Executable Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx Before running shell scripts, it's crucial to make them executable. This command grants execute permissions to all .sh files in the current directory. ```bash chmod +x *.sh ``` -------------------------------- ### Install and Use Axiom CLI for Log Ingestion (Bash) Source: https://github.com/rybbit-io/rybbit/blob/master/server/AXIOM_SETUP.md This bash script demonstrates how to install the Axiom CLI and pipe application logs to Axiom for ingestion. It requires the Axiom dataset name and token to be set as environment variables. ```bash # Install axiom CLI curl -fsSL https://install.axiom.co/install.sh | sh # Run your app and pipe to Axiom npm start | axiom ingest $AXIOM_DATASET -t $AXIOM_TOKEN ``` -------------------------------- ### Install Rybbit JS SDK using npm or yarn Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/sdks/web.mdx Installs the Rybbit JavaScript SDK using either npm or yarn package managers. This is the first step before initializing the SDK in your project. ```bash npm install @rybbit/js ``` ```bash yarn add @rybbit/js ``` -------------------------------- ### Start Rybbit Services Without Caddy Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Starts specific Rybbit services (backend, client, databases) using Docker Compose, excluding Caddy. This is used when an external reverse proxy handles SSL and routing. ```bash docker compose up -d backend client clickhouse postgres ``` -------------------------------- ### Restarting Rybbit After Cleanup (Bash) Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/troubleshooting.mdx These bash commands guide you through restarting Rybbit after a cleanup. It involves copying the example environment file, editing it with your specific configuration, and then starting the Docker services in detached mode. ```bash # Copy environment file cp .env.example .env # Edit .env with your configuration # Then start the services docker-compose up -d ``` -------------------------------- ### Direct Node.js Execution (Bash) Source: https://github.com/rybbit-io/rybbit/blob/master/monitor-agent/README.md Outlines the steps to set up and run the monitor agent directly using Node.js. This involves installing dependencies, building the project, and starting the application. ```bash # Install dependencies npm install # Build npm run build # Run npm start ``` -------------------------------- ### Stop Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx This script is used to gracefully stop all running Rybbit services. ```bash ./stop.sh ``` -------------------------------- ### Configure Firewall using ufw on Ubuntu Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting.mdx This snippet demonstrates how to configure the Uncomplicated Firewall (ufw) on Ubuntu to allow necessary incoming connections, specifically SSH and HTTPS traffic. It is crucial to allow SSH before enabling the firewall to prevent lockout. ```bash sudo ufw allow ssh # Keep SSH access (usually port 22) sudo ufw allow 443/tcp # Allow HTTPS traffic sudo ufw enable # Enable the firewall sudo ufw status # Check the status ``` -------------------------------- ### Direct Axiom Logging Setup in Development (Bash) Source: https://github.com/rybbit-io/rybbit/blob/master/server/AXIOM_SETUP.md Run your development server with Axiom credentials as environment variables to send logs directly to Axiom. This is useful for testing your Axiom integration during development. ```bash AXIOM_DATASET=your-dataset AXIOM_TOKEN=your-token npm run dev ``` -------------------------------- ### Install Certbot and Nginx Plugin Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Installs Certbot and its Nginx plugin using package managers for Ubuntu/Debian and CentOS/RHEL systems, required for obtaining Let's Encrypt SSL certificates. ```bash # Ubuntu/Debian sudo apt update sudo apt install certbot python3-certbot-nginx # CentOS/RHEL sudo yum install certbot python3-certbot-nginx ``` -------------------------------- ### Initialize Rybbit SDK with configuration Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/sdks/web.mdx Example of initializing the Rybbit SDK with essential configuration options. The `init` method must be called before other tracking methods. It requires `analyticsHost` and `siteId`. ```javascript import rybbit from "@rybbit/js"; rybbit.init({ analyticsHost: "https://api.rybbit.io/api", siteId: "1", }); ``` -------------------------------- ### Download Rybbit Configuration Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx This command downloads the ClickHouse configuration for Rybbit directly from its GitHub repository using curl and extracts it. Ensure you have curl and tar installed. ```bash curl -L https://github.com/rybbit-io/rybbit/archive/master.tar.gz | tar -xz --strip=2 rybbit-master/clickhouse_config ``` -------------------------------- ### Docker Compose Configuration for Coolify Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-manual.mdx This docker-compose.yaml file is specifically tailored for deployment with Coolify. It removes Caddy dependencies, adds Traefik network labels to services, and modifies backend and client service definitions to work correctly with Coolify's proxy setup. It includes configurations for ClickHouse, PostgreSQL, the Rybbit backend, and the Rybbit client. ```yaml services: clickhouse: container_name: clickhouse image: clickhouse/clickhouse-server:25.4.2 volumes: - clickhouse-data:/var/lib/clickhouse configs: - source: clickhouse_network target: /etc/clickhouse-server/config.d/network.xml - source: clickhouse_json target: /etc/clickhouse-server/config.d/enable_json.xml - source: clickhouse_logging target: /etc/clickhouse-server/config.d/logging_rules.xml - source: clickhouse_user_logging target: /etc/clickhouse-server/config.d/user_logging.xml environment: - CLICKHOUSE_DB=${CLICKHOUSE_DB:-analytics} - CLICKHOUSE_USER=${CLICKHOUSE_USER:-default} - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog} healthcheck: test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping", ] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped labels: - traefik.enable=false postgres: image: postgres:17.4 container_name: postgres environment: - POSTGRES_USER=${POSTGRES_USER:-frog} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-frog} - POSTGRES_DB=${POSTGRES_DB:-analytics} volumes: - postgres-data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped labels: - traefik.enable=false backend: image: ghcr.io/rybbit-io/rybbit-backend:${IMAGE_TAG:-latest} container_name: backend environment: - NODE_ENV=production - CLICKHOUSE_HOST=http://clickhouse:8123 - CLICKHOUSE_DB=${CLICKHOUSE_DB:-analytics} - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog} - POSTGRES_HOST=postgres - POSTGRES_PORT=5432 - POSTGRES_DB=${POSTGRES_DB:-analytics} - POSTGRES_USER=${POSTGRES_USER:-frog} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-frog} - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} - BASE_URL=${BASE_URL} - DOMAIN_NAME=${DOMAIN_NAME} - DISABLE_SIGNUP=${DISABLE_SIGNUP} - DISABLE_TELEMETRY=${DISABLE_TELEMETRY} depends_on: clickhouse: condition: service_healthy postgres: condition: service_started healthcheck: test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3001/api/health", ] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped labels: - traefik.enable=true - traefik.docker.network=coolify - traefik.http.routers.rybbit-backend.entrypoints=https - traefik.http.routers.rybbit-backend.tls=true - traefik.http.routers.rybbit-backend.rule=Host(`${DOMAIN_NAME}`) && (Path(`/api`) || PathPrefix(`/api/`)) - traefik.http.services.rybbit-backend.loadbalancer.server.port=3001 - traefik.http.routers.rybbit-backend.priority=100 - traefik.http.middlewares.rybbit-forward-headers.headers.customrequestheaders.X-Forwarded-Proto=https - traefik.http.middlewares.rybbit-forward-headers.headers.customrequestheaders.X-Forwarded-Host=${DOMAIN_NAME} - traefik.http.routers.rybbit-backend.middlewares=rybbit-forward-headers client: image: ghcr.io/rybbit-io/rybbit-client:${IMAGE_TAG:-latest} container_name: client environment: - NODE_ENV=production - NEXT_PUBLIC_BACKEND_URL=${BASE_URL} - NEXT_PUBLIC_DISABLE_SIGNUP=${DISABLE_SIGNUP} - DOMAIN_NAME=${DOMAIN_NAME} depends_on: - backend restart: unless-stopped labels: - traefik.enable=true - traefik.docker.network=coolify - traefik.http.routers.rybbit-client.entrypoints=https - traefik.http.routers.rybbit-client.tls=true - traefik.http.routers.rybbit-client.rule=Host(`${DOMAIN_NAME}`) - traefik.http.services.rybbit-client.loadbalancer.server.port=3002 - traefik.http.routers.rybbit-client.priority=10 volumes: clickhouse-data: postgres-data: redis-data: configs: clickhouse_network: content: | 0.0.0.0 clickhouse_json: content: | 1 ``` -------------------------------- ### Install Dependencies with npm Source: https://github.com/rybbit-io/rybbit/blob/master/server/README.md Installs all project dependencies using npm. Ensure Node.js and npm are installed and meet the version requirements. ```bash npm install ``` -------------------------------- ### Structured Log Example (JavaScript) Source: https://github.com/rybbit-io/rybbit/blob/master/server/AXIOM_SETUP.md This JavaScript snippet demonstrates how to log structured data using a logger instance. The first parameter is an object containing structured data, followed by the log message. Supports multiple log levels. ```javascript logger.info({ monitorId: 123, region: "us-east-1" }, "Health check completed"); ``` -------------------------------- ### Run Development Server with Next.js Source: https://github.com/rybbit-io/rybbit/blob/master/client/README.md These commands initiate the development server for the Next.js project. Ensure you have Node.js installed and the project dependencies are set up. The server typically runs on http://localhost:3000. ```bash npm run dev ``` ```bash yarn dev ``` ```bash pnpm dev ``` ```bash bun dev ``` -------------------------------- ### Install Rybbit Node.js SDK Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/sdks/node.mdx Installs the Rybbit Node.js SDK using either npm or yarn package managers. This is the first step to integrating Rybbit into your Node.js application. ```bash npm install @rybbit/node ``` ```bash yarn add @rybbit/node ``` -------------------------------- ### Basic Rybbit Tracking Script Installation Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/script.mdx This is the basic HTML script tag required to integrate the Rybbit tracking script into your website. It should be placed within the `` section of your HTML. Replace 'YOUR_SITE_ID' with your actual site ID. The `async` attribute ensures the script loads without blocking page rendering. ```html ``` -------------------------------- ### Verify Rybbit and Nginx Setup Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Commands to check the status of the Nginx service, Rybbit's Docker containers, and to perform an initial test of the website via curl. ```bash # Check Nginx status sudo systemctl status nginx # Check Rybbit services docker compose ps # Test the website curl -I https://your.domain.name ``` -------------------------------- ### Rybbit Tracker Setup in Dart (Flutter) Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/api.mdx Provides initial imports for setting up the Rybbit tracker in a Flutter application using Dart. It includes necessary libraries for HTTP requests, JSON encoding, platform-specific information, and device details. This snippet serves as a starting point for building the tracker functionality in Flutter. ```dart import 'package:http/http.dart' as http; import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:device_info_plus/device_info_plus.dart'; ``` -------------------------------- ### Disabling Built-in Webserver with Rybbit Setup Script Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-advanced.mdx To use your own web server with Rybbit, the setup script provides the `--no-webserver` flag. This prevents the Caddy container from starting and allows external services to manage traffic to Rybbit's backend and client ports. ```bash ./setup.sh your.domain.name --no-webserver ``` -------------------------------- ### Axiom Processing Language (APL) Query Examples Source: https://github.com/rybbit-io/rybbit/blob/master/server/AXIOM_SETUP.md Examples of Axiom Processing Language (APL) queries to filter logs within your Axiom dataset. These queries allow you to view all errors, logs from a specific service, or logs related to a particular monitor ID. ```apl // View all errors | where level == "error" // View logs from a specific service | where service == "notification-service" // View logs for a specific monitor | where monitorId == 123 ``` -------------------------------- ### Troubleshooting Rybbit Service Status Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx These bash commands are used to troubleshoot services that won't start or to check the status of running services in a Docker Compose environment. `docker compose logs` shows the logs for all services, while `docker compose ps` lists the running services and their states. ```bash # Check logs docker compose logs # Check service status docker compose ps ``` -------------------------------- ### Check Docker Compose Service Logs Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-manual.mdx This bash command is used to view the logs of all services defined in a docker-compose.yaml file. It's a fundamental troubleshooting step to diagnose why services might not be starting or behaving as expected. ```bash docker compose logs ``` -------------------------------- ### Run Rybbit with Custom Ports Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Starts Rybbit without the webserver, specifying custom ports for the backend and client services. This allows flexibility when default ports are in use. ```bash ./setup.sh your.domain.name --no-webserver --backend-port 8080 --client-port 8081 ``` -------------------------------- ### Rybbit Tracking Script with Multiple Configuration Options Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/script.mdx This example demonstrates how to use the Rybbit tracking script with several advanced configuration options. These options, set as `data-*` attributes on the script tag, allow for fine-grained control over tracking behavior, including skipping/masking patterns, disabling query tracking, enabling session replay, error tracking, Web Vitals, and setting a debounce interval. ```html ``` -------------------------------- ### Docker Compose Deployment for Rybbit Monitor Agent Source: https://github.com/rybbit-io/rybbit/blob/master/monitor-agent/DEPLOYMENT.md This snippet details deploying the Rybbit Monitor Agent using Docker Compose. It includes downloading the necessary compose files, starting the services with specific region configurations, and checking the service status and logs. It assumes Caddy is used for SSL. ```bash # Download docker-compose files wget https://raw.githubusercontent.com/your-repo/rybbit/main/monitor-agent/docker-compose.yml wget https://raw.githubusercontent.com/your-repo/rybbit/main/monitor-agent/docker-compose.prod.yml wget https://raw.githubusercontent.com/your-repo/rybbit/main/monitor-agent/Caddyfile # Start the services REGION=us-east docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d # Check status docker compose ps docker compose logs -f ``` -------------------------------- ### List Containers with Network Information Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Displays a table of running containers, showing their names and the networks they are connected to. This helps in verifying network connectivity for troubleshooting. ```bash docker ps --format "table {{.Names}}\t{{.Networks}}" ``` -------------------------------- ### Configure Rybbit Script with Advanced Attributes (HTML) Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/script.mdx An example of the Rybbit tracking script tag with advanced configuration attributes for skipping and masking URL patterns, and debouncing pageview tracking. These attributes allow for granular control over what is tracked and how privacy is maintained. ```html ``` -------------------------------- ### List Docker Networks Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Lists all Docker networks currently available on the system. This is a fundamental command for network troubleshooting. ```bash docker network ls ``` -------------------------------- ### Install JavaScript Tracking Script Source: https://context7.com/rybbit-io/rybbit/llms.txt Instructions for adding the Rybbit JavaScript tracking script to a website. Includes basic installation and full configuration options for automatic tracking of pageviews, SPA navigation, outbound clicks, errors, web vitals, and session replays. ```html ``` -------------------------------- ### Enable and Reload Nginx Site Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Commands to enable a new Nginx site configuration by creating a symbolic link and then testing and reloading the Nginx service to apply changes. ```bash # Create symlink to enable the site sudo ln -s /etc/nginx/sites-available/your-site /etc/nginx/sites-enabled/ # Test the configuration sudo nginx -t # Reload Nginx sudo systemctl reload nginx ``` -------------------------------- ### Run Application with npm Source: https://github.com/rybbit-io/rybbit/blob/master/server/README.md Commands to run the Rybbit analytics backend application. 'npm run dev' is for development mode, while 'npm run build' followed by 'npm start' is for production. ```bash # Development mode npm run dev ``` ```bash # Production build npm run build npm start ``` -------------------------------- ### Rybbit Tracker Usage Example (Dart) Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/api.mdx Example demonstrating how to initialize and use the RybbitTracker in a Flutter application to track page views and custom events. It showcases tracking an app launch and a button click event. ```dart // Usage void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { final tracker = RybbitTracker(); @override void initState() { super.initState(); // Track app launch once when the app initializes tracker.trackEvent({ 'type': 'pageview', 'pathname': '/api/users', 'hostname': 'api.example.com', 'page_title': 'User API Endpoint', }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: ElevatedButton( onPressed: () { // Track custom event tracker.trackEvent({ 'type': 'custom_event', 'pathname': '/checkout', 'event_name': 'purchase', 'properties': json.encode({'amount': 99.99, 'currency': 'USD'}), }); }, child: Text('Track Event'), ), ), ), ); } } ``` -------------------------------- ### Copying ClickHouse Configuration Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/nginx-proxy-manager.mdx Optional commands to copy the ClickHouse configuration files. This allows for more granular control over ClickHouse settings. You can either copy from a local repository clone or download directly. ```bash # If you cloned the main repo, copy the config cp -r /path/to/rybbit/clickhouse_config ./ # Or download it directly curl -L https://github.com/rybbit-io/rybbit/archive/master.tar.gz | tar -xz --strip=2 rybbit-master/clickhouse_config ``` -------------------------------- ### Verify SSL Certificates Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Command to list all SSL certificates managed by Certbot, helpful for troubleshooting SSL certificate-related errors. ```bash sudo certbot certificates ``` -------------------------------- ### Follow Nginx Proxy Manager Logs Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Continuously streams logs from the Nginx Proxy Manager container. You may need to adjust the container name ('nginx-proxy-manager') if it differs in your setup. Press Ctrl+C to stop. ```bash docker logs -f nginx-proxy-manager ``` -------------------------------- ### Refactored Service Logging (TypeScript) Source: https://github.com/rybbit-io/rybbit/blob/master/server/src/lib/logger/LOGGING.md Provides an example of refactoring old `console.log` statements to use a structured logger within a service class. It shows the 'before' and 'after' of a service starting and handling an error. ```typescript import { createServiceLogger } from "../../lib/logger/logger.js"; class MyService { private logger = createServiceLogger("my-service"); start() { this.logger.info("Service starting..."); } handleError(error: Error) { this.logger.error(error, "Failed to connect"); } } ``` -------------------------------- ### Troubleshoot Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Commands to check the status and view logs of Rybbit's Docker containers, useful for diagnosing issues like '502 Bad Gateway'. ```bash docker compose ps docker compose logs ``` -------------------------------- ### Common Rybbit Event Tracking Examples (JavaScript) Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/guides/google-tag-manager.mdx A collection of JavaScript code examples for tracking various common user interactions using Rybbit's `event` function. These include form submissions, e-commerce 'add to cart' actions, video engagement, and file downloads, each with specific data payloads. ```javascript // Form submission window.rybbit.event('form_submitted', { form_id: 'contact-form', form_name: 'Contact Us' }); // E-commerce tracking window.rybbit.event('add_to_cart', { product_id: '12345', product_name: 'Example Product', price: 29.99, quantity: 1 }); // Video engagement window.rybbit.event('video_played', { video_title: 'Product Demo', duration: 120, percent_watched: 75 }); // Download tracking window.rybbit.event('file_downloaded', { file_name: 'whitepaper.pdf', file_type: 'pdf', file_size: '2.5MB' }); ``` -------------------------------- ### Docker Compose Log Monitoring Commands Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/nginx-proxy-manager.mdx Bash commands for monitoring logs of Rybbit services and Nginx Proxy Manager containers. Essential for debugging. ```bash # Rybbit services docker compose logs -f # Specific service docker compose logs -f rybbit_backend # NPM logs (adjust container name) docker logs -f nginx-proxy-manager ``` -------------------------------- ### Set Axiom Environment Variables (.env file) Source: https://github.com/rybbit-io/rybbit/blob/master/server/AXIOM_SETUP.md Configure your Axiom dataset name and API token by adding these environment variables to your .env file. Ensure the token has ingest permissions and the dataset name is accurate. ```env AXIOM_DATASET=your-dataset-name AXIOM_TOKEN=xaat-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` -------------------------------- ### Docker Network Inspection Commands Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/nginx-proxy-manager.mdx Bash commands to inspect Docker networks and containers, useful for diagnosing network connectivity issues with Rybbit services. ```bash # List all networks docker network ls # Inspect the npm_proxy network docker network inspect npm_proxy # Check which containers are connected docker ps --format "table {{.Names}}\t{{.Networks}}" ``` -------------------------------- ### Inspect Docker Network Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Provides detailed information about a specific Docker network, including which containers are connected to it and their network configurations. Replace 'npm_proxy' with the actual network name. ```bash docker network inspect npm_proxy ``` -------------------------------- ### Verify Docker Compose Service Status Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Checks the running status of all services managed by Docker Compose for the Rybbit project. This command is used to ensure all containers are up and running as expected. ```bash docker compose ps ``` -------------------------------- ### Follow Specific Rybbit Service Logs Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Continuously streams logs from a specific Rybbit service (e.g., 'rybbit_backend'). Replace 'rybbit_backend' with the desired service name. Press Ctrl+C to stop. ```bash docker compose logs -f rybbit_backend ``` -------------------------------- ### User Identification Workflow Example Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/track-events.mdx Demonstrates a typical workflow for handling user login and logout events, including setting and clearing user IDs and tracking associated events. ```javascript // When user logs in function handleLogin(userData) { // Set user identification window.rybbit.identify(userData.id); // Track login event window.rybbit.event("User Login", { method: "email", plan: userData.plan }); } // When user logs out function handleLogout() { // Track logout event window.rybbit.event("User Logout"); // Clear user identification window.rybbit.clearUserId(); } // Check identification status function checkUserStatus() { const userId = window.rybbit.getUserId(); if (userId) { console.log("User is identified:", userId); } else { console.log("Anonymous user"); } } ``` -------------------------------- ### Nginx Configuration for Rybbit Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Provides an Nginx server block configuration to proxy requests to the Rybbit backend and client services. It includes redirection from HTTP to HTTPS and specific routing for API requests. ```nginx server { listen 80; server_name your.domain.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name your.domain.com; # Your SSL configuration here location /api/ { proxy_pass http://localhost:3001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location / { proxy_pass http://localhost:3002; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` -------------------------------- ### Log Server-Level Events (TypeScript) Source: https://github.com/rybbit-io/rybbit/blob/master/server/src/lib/logger/LOGGING.md Shows how to use `server.log` to log critical server-wide events such as startup messages and shutdown errors. This is useful for monitoring the overall health and status of the application. ```typescript server.log.info("Server started on port 3001"); server.log.error(error, "Shutdown error"); ``` -------------------------------- ### Traefik Proxy Configuration for Rybbit Services Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/nginx-proxy-manager.mdx Traefik labels for configuring routing and SSL for Rybbit backend and client services. Assumes Traefik is managing SSL certificates via Let's Encrypt. ```yaml services: rybbit_backend: # ... existing config labels: - "traefik.enable=true" - "traefik.http.routers.rybbit-api.rule=Host(`your.domain.com`) && PathPrefix(`/api`)" - "traefik.http.routers.rybbit-api.tls.certresolver=letsencrypt" - "traefik.http.services.rybbit-api.loadbalancer.server.port=3001" - "traefik.docker.network=traefik_proxy" rybbit_client: # ... existing config labels: - "traefik.enable=true" - "traefik.http.routers.rybbit-client.rule=Host(`your.domain.com`)" - "traefik.http.routers.rybbit-client.tls.certresolver=letsencrypt" - "traefik.http.services.rybbit-client.loadbalancer.server.port=3002" - "traefik.docker.network=traefik_proxy" networks: traefik_proxy: external: true ``` -------------------------------- ### Bash: Create Docker Network for NPM Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Command to create a Docker network named 'npm_proxy' which is required for Nginx Proxy Manager to communicate with the Rybbit containers. This command is executed in the terminal. ```bash docker network create npm_proxy ``` -------------------------------- ### Create Rybbit Environment File (.env) Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Defines essential environment variables for Rybbit, including domain name, base URL, authentication secret, and optional settings for signup, ports, and database credentials. This file configures the Rybbit instance. ```env # Required: Your domain and base URL DOMAIN_NAME=your.domain.com BASE_URL=https://your.domain.com # Required: Authentication secret (generate a random 32+ character string) BETTER_AUTH_SECRET=your-very-long-random-secret-string-here # Optional: Disable new user signups after creating admin account DISABLE_SIGNUP=false # Optional: Custom ports (only needed if you want different ports) # HOST_BACKEND_PORT="3001:3001" # HOST_CLIENT_PORT="3002:3002" # Optional: Database credentials (defaults work fine) # CLICKHOUSE_PASSWORD=frog # POSTGRES_USER=frog # POSTGRES_PASSWORD=frog # POSTGRES_DB=analytics # CLICKHOUSE_DB=analytics ``` -------------------------------- ### Obtain SSL Certificate with Certbot Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Uses Certbot to automatically obtain and install an SSL certificate for a specified domain, configuring Nginx to use it. ```bash sudo certbot --nginx -d your.domain.name ``` -------------------------------- ### Docker Compose Override for Exposing Ports Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx Defines a docker-compose.override.yml file to specify ports for the backend and client services. This method is an alternative to modifying the .env file for exposing ports when using an external reverse proxy. ```yaml services: backend: ports: - "3001:3001" client: ports: - "3002:3002" ``` -------------------------------- ### Nginx Configuration for Custom Ports Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-guides/custom-nginx.mdx Modifies the Nginx proxy configuration to direct traffic to the custom backend and client ports specified when starting Rybbit. ```nginx location /api/ { proxy_pass http://localhost:8080; # Custom backend port # ... rest of config } location / { proxy_pass http://localhost:8081; # Custom client port # ... rest of config } ``` -------------------------------- ### Docker Compose Configuration for Rybbit Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/self-hosting-manual.mdx This snippet shows the `docker-compose.yaml` file structure for deploying Rybbit. It defines volumes for data persistence and configuration files for ClickHouse, including network settings, JSON type enablement, logging, and user logging profiles. Ensure 'Escape special characters in labels' is unchecked in Coolify for proper environment variable reading. ```yaml volumes: clickhouse-data: postgres-data: redis-data: configs: clickhouse_network: content: | 0.0.0.0 clickhouse_json: content: | 1 clickhouse_logging: content: | warning true clickhouse_user_logging: content: | 0 0 0 ``` -------------------------------- ### Initialize Rybbit Node.js SDK Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/sdks/node.mdx Initializes the Rybbit SDK with necessary configuration including analytics host, site ID, and API key. The constructor validates these required options to ensure proper operation. ```typescript import { Rybbit } from "@rybbit/node"; const rybbit = new Rybbit(config: RybbitConfig); ``` ```javascript import { Rybbit } from "@rybbit/node"; const rybbit = new Rybbit({ analyticsHost: "https://api.rybbit.io/api", siteId: "1", apiKey: "your-secret-api-key", }); ``` -------------------------------- ### Docker Compose for Rybbit with Databases Source: https://github.com/rybbit-io/rybbit/blob/master/docs-v2/content/docs/self-hosting-guides/nginx-proxy-manager.mdx Defines the services for Rybbit, including ClickHouse and PostgreSQL databases, the backend API, and the frontend client. It specifies Docker images, container names, volumes, environment variables, health checks, restart policies, and network configurations. Dependencies between services are managed to ensure proper startup order. ```yaml services: rybbit_clickhouse: image: clickhouse/clickhouse-server:25.4.2 container_name: rybbit_clickhouse volumes: - ./clickhouse-data:/var/lib/clickhouse - ./clickhouse_config:/etc/clickhouse-server/config.d environment: - CLICKHOUSE_DB=${CLICKHOUSE_DB:-analytics} - CLICKHOUSE_USER=${CLICKHOUSE_USER:-default} - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog} healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped networks: - internal rybbit_postgres: image: postgres:17.4 container_name: rybbit_postgres environment: - POSTGRES_USER=${POSTGRES_USER:-frog} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-frog} - POSTGRES_DB=${POSTGRES_DB:-analytics} volumes: - ./postgres-data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped networks: - internal rybbit_backend: image: ghcr.io/rybbit-io/rybbit-backend:${IMAGE_TAG:-latest} container_name: rybbit_backend environment: - NODE_ENV=production - CLICKHOUSE_HOST=http://rybbit_clickhouse:8123 - CLICKHOUSE_DB=${CLICKHOUSE_DB:-analytics} - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog} - POSTGRES_HOST=rybbit_postgres - POSTGRES_PORT=5432 - POSTGRES_DB=${POSTGRES_DB:-analytics} - POSTGRES_USER=${POSTGRES_USER:-frog} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-frog} - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} - BASE_URL=${BASE_URL} - DISABLE_SIGNUP=${DISABLE_SIGNUP} depends_on: rybbit_clickhouse: condition: service_healthy rybbit_postgres: condition: service_started healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3001/api/health"] interval: 3s timeout: 5s retries: 5 start_period: 10s restart: unless-stopped networks: - internal - npm_proxy rybbit_client: image: ghcr.io/rybbit-io/rybbit-client:${IMAGE_TAG:-latest} container_name: rybbit_client environment: - NODE_ENV=production - NEXT_PUBLIC_BACKEND_URL=${BASE_URL} - NEXT_PUBLIC_DISABLE_SIGNUP=${DISABLE_SIGNUP} depends_on: - rybbit_backend restart: unless-stopped networks: - internal - npm_proxy networks: internal: driver: bridge npm_proxy: external: true volumes: clickhouse-data: postgres-data: ``` -------------------------------- ### Initialize Rybbit SDK with configuration Source: https://github.com/rybbit-io/rybbit/blob/master/docs/src/content/sdks/web.mdx Initializes the Rybbit SDK with required configuration options such as `analyticsHost` and `siteId`. This must be called before any other tracking methods. The `config` object can also include optional settings like `debounce`, `autoTrackPageviews`, and `debug` to customize tracking behavior. ```typescript rybbit.init(config: RybbitConfig); ``` ```javascript import rybbit from "@rybbit/js"; rybbit.init({ analyticsHost: "https://api.rybbit.io/api", siteId: "1", }); ```