diff --git a/.env b/.env index d323e58..90d5237 100644 --- a/.env +++ b/.env @@ -86,3 +86,9 @@ # Sets the file to write access logs to. Note, this is the directory used within the Docker container # VALENTINA_WEBUI_ACCESS_LOG=/valentina/access.log + +# Enables Cloudflare Web Analytics by setting this to your Cloudflare Web Analytics token +# VALENTINA_CLOUDFLARE_WEB_ANALYTICS_TOKEN= + +# Enables Google Analytics by setting this to your Google Analytics ID +# VALENTINA_GOOGLE_ANALYTICS_ID= diff --git a/README.md b/README.md index e94a5d6..99cc4e3 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ Settings for Valentina are controlled by environment variables. The following is | VALENTINA_DISCORD_OAUTH_CLIENT_ID | | Sets the ID for the Discord OAuth. This is required to run the web UI. | | VALENTINA_WEBUI_BEHIND_REVERSE_PROXY | `false` | Set to `true` if the web UI is behind a reverse proxy. | | VALENTINA_WEBUI_ACCESS_LOG | `/valentina/access.log` | Sets the file to write access logs to.
Note, this is the directory used within the Docker container | +| VALENTINA_CLOUDFLARE_WEB_ANALYTICS_TOKEN | | Optional: Enable Cloudflare Web Analytics by setting this to your Cloudflare Web Analytics token | +| VALENTINA_GOOGLE_ANALYTICS_ID | | Optional: Enable Google Analytics by setting this to your Google Analytics ID | --- diff --git a/src/valentina/utils/config.py b/src/valentina/utils/config.py index f7734bd..868a941 100644 --- a/src/valentina/utils/config.py +++ b/src/valentina/utils/config.py @@ -66,6 +66,8 @@ class ValentinaConfig(BaseConfig): # type: ignore [misc] redis_addr: str = "127.0.0.1:6379" webui_secret_key: str = "" webui_behind_reverse_proxy: ENV_BOOLEAN = False + cloudflare_web_analytics_token: str = "" + google_analytics_id: str = "" CONFIG_SOURCES: ClassVar[ConfigSources | None] = [ EnvSource(prefix="VALENTINA_", file=PROJECT_ROOT_PATH / ".env", allow_all=True), diff --git a/src/valentina/webui/config.py b/src/valentina/webui/config.py index 6326e6a..a1e612a 100644 --- a/src/valentina/webui/config.py +++ b/src/valentina/webui/config.py @@ -11,6 +11,8 @@ class Config: DISCORD_CLIENT_SECRET = ValentinaConfig().discord_oauth_secret DISCORD_REDIRECT_URI = f"{ValentinaConfig().webui_base_url}/callback" DISCORD_BOT_TOKEN = ValentinaConfig().discord_token + CLOUDFLARE_WEB_ANALYTICS_TOKEN = ValentinaConfig().cloudflare_web_analytics_token + GOOGLE_ANALYTICS_ID = ValentinaConfig().google_analytics_id class Production(Config): diff --git a/src/valentina/webui/shared/PageLayout.jinja b/src/valentina/webui/shared/PageLayout.jinja index 96091bd..8509e83 100644 --- a/src/valentina/webui/shared/PageLayout.jinja +++ b/src/valentina/webui/shared/PageLayout.jinja @@ -43,6 +43,19 @@ + {% if config.GOOGLE_ANALYTICS_ID %} + + + + + {% endif %} {# include nav bar only when user is logged in #} {% if session["USER_ID"] is defined and session["GUILD_ID"] is defined %}{% endif %} @@ -139,5 +152,12 @@ var toastE = new bootstrap.Toast(toast); toastE.show(); + {% if config.CLOUDFLARE_WEB_ANALYTICS_TOKEN %} + + + + {% endif %}