Swetrix
Self-hosting

Configuring

The easiest way to get started with Swetrix is by using our cloud service. We do all the dirty work for you: hosting, maintenance, backups, worldwide CDN, etc. Using Cloud you still own the data, you can export it or delete it at any time you want. By using Swetrix Cloud you support maintenance and development of the product, which eventually makes it better.

The following environment variables are available for configuration:

Frontend (swetrix image)

VariableDefaultDescription
BASE_URLhttp://localhost:8080/Public URL of your Swetrix CE instance.

The BASE_URL must be publicly reachable from your users' browsers. Do not set it to a Docker network hostname like http://swetrix-api:8080 or http://swetrix-api:5005. Use a public domain or IP that resolves from the internet, for example https://statistics.example.com.

Backend (swetrix-api image)

Basic configuration

VariableDefaultDescription
SECRET_KEY_BASEauto-generated by configure.shSecret used for auth keys and login sessions. Must be set.
BASE_URLPublic URL of your Swetrix CE instance, e.g. https://analytics.example.com. Used by the API to build OAuth redirect URIs for Google integrations. Required to enable Google Search Console and Google Analytics import.
CLIENT_IP_HEADERnullDefines what header should be used to get IP address (e.g. cf-connecting-ip, x-real-ip, etc.). If not set, Swetrix will use x-forwarded-for header.
DISABLE_REGISTRATIONtrueWhen set to true - Swetrix will disable user registration, except for the initial user.
IP_GEOLOCATION_DB_PATH``Path to the .mmdb file for IP geolocation database. By default Swetrix uses the IP to City Lite database by DB-IP, which provides country / region / city only. To populate the Network intelligence panel (ISP, organisation, usage type, connection type), point this at a paid MaxMind GeoIP2 ISP / Insights database or a paid DB-IP database that includes those fields.
IS_PRIMARY_NODEtrueYou should not touch this variable unless you know what you are doing. It's used to spin off multiple API instances in a cluster, where only one of them will be primary. If changed to false, things like cron task manager will be disabled for this instance.
TWO_FACTOR_AUTHENTICATION_APP_NAMESwetrix CEThe app name shown in authenticator apps when users set up 2FA.

Email configuration (SMTP)

Swetrix will send transactional emails for some actions, like password reset or project invitations. You must configure SMTP credentials for this to work correctly.

VariableDefaultDescription
SMTP_HOSTSMTP host
SMTP_PORTSMTP port
SMTP_USERSMTP user (if your SMTP provider requires authentication)
SMTP_PASSWORDSMTP password (if your SMTP provider requires authentication)
FROM_EMAILEmail address to use for sending emails
SMTP_MOCKfalseIf set to true - emails will not be sent, but will be logged to the console instead

If you don't have an SMTP provider, some regular email providers offer this functionality. For example, you can configure Gmail for app specific passwords and use them as SMTP credentials (in this case, the SMTP_HOST should be smtp.gmail.com with port 587).

Google Search Console integration

To let users connect their Google Search Console account from project settings (and populate the SEO dashboard), the API needs an OAuth client created in your own Google Cloud project. The full step-by-step guide lives in Google Search Console; the relevant variables are:

VariableDefaultDescription
GOOGLE_GSC_CLIENT_IDOAuth 2.0 Client ID issued by the Google Cloud console for your Swetrix instance.
GOOGLE_GSC_CLIENT_SECRETOAuth 2.0 Client secret matching GOOGLE_GSC_CLIENT_ID.
BASE_URLPublic URL of your Swetrix CE instance. The API uses ${BASE_URL}/gsc-connected as the OAuth redirect URI; it must match the URI registered in the Google Cloud console.

If any of these are unset the SEO tab still shows up but the integrations card displays a "not configured" notice instead of the Connect button.

Google Analytics import

To import data from Google Analytics 4, the API needs an OAuth client created in your own Google Cloud project. The full step-by-step guide lives in Google Analytics import; the relevant variables are:

VariableDefaultDescription
GOOGLE_GA4_CLIENT_IDOAuth 2.0 Client ID issued by the Google Cloud console for your Swetrix instance.
GOOGLE_GA4_CLIENT_SECRETOAuth 2.0 Client secret matching GOOGLE_GA4_CLIENT_ID.
BASE_URLPublic URL of your Swetrix CE instance. The API uses ${BASE_URL}/ga4-import-connected as the OAuth redirect URI; it must match the URI registered in the Google Cloud console.

If any of these are unset, Google Analytics import requests fail with a "not configured" error.

OIDC configuration

Swetrix Community Edition also supports OIDC authentication. To enable it, you need to set the following variables:

VariableDefaultDescription
OIDC_ENABLEDfalseMust be set to true to enable OIDC authentication.
OIDC_ONLY_AUTHfalseIf set to true - Swetrix will only allow users to authenticate via OIDC (i.e. regular login / registration form will not work).
OIDC_DISCOVERY_URLURL of the OIDC discovery endpoint, for example https://example.com/.well-known/openid-configuration
OIDC_CLIENT_IDOIDC client ID
OIDC_CLIENT_SECRETOIDC client secret
OIDC_PROMPTselect_accountOIDC prompt

Redis

VariableDefaultDescription
REDIS_PASSWORDpasswordRedis password
REDIS_PORT6379Redis port
REDIS_USERdefaultRedis user

Clickhouse

VariableDefaultDescription
CLICKHOUSE_DATABASEanalyticsClickHouse database
CLICKHOUSE_USERdefaultClickHouse user
CLICKHOUSE_PORT8123ClickHouse port
CLICKHOUSE_PASSWORDGeneratedClickHouse password

On this page