diff --git a/.env.example b/.env.example
index ce66f4f..92211b4 100644
--- a/.env.example
+++ b/.env.example
@@ -14,3 +14,6 @@ BADGE_API_URL=http://localhost:8081
# https://www.steamgriddb.com/api/v2, if you want games to have images
STEAMGRIDDB_API_KEY=steamgrid_api_key
+
+# https://plausible.io
+PLAUSIBLE_SCRIPT_HTML=''
diff --git a/README.md b/README.md
index 1744413..42d9f64 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ https://git.creations.works/creations/badgeAPI
### 4. SteamGridDB
->You only have to use this if you want to fetch game icons that Discord doesn’t provide:
+>Only needed if you want to fetch game icons that Discord doesn’t provide:
https://www.steamgriddb.com/api/v2
---
@@ -87,6 +87,28 @@ bun run start
---
+## Optional: Analytics with Plausible
+
+You can enable [Plausible Analytics](https://plausible.io) tracking by setting a script snippet in your environment.
+
+### `.env` Variable
+
+| Variable | Description |
+|-------------------------|------------------------------------------------------------------------|
+| `PLAUSIBLE_SCRIPT_HTML` | Full `'
+```
+
+- The script will only be injected if this variable is set.
+- Plausible provides the correct script when you add a domain.
+- Be sure to wrap it in single quotes (`'`) so it works in `.env`.
+
+---
+
## Docker Support
### Build & Start with Docker Compose
@@ -103,10 +125,10 @@ Make sure the `.env` file is configured correctly before starting the container.
These are the main public routes exposed by the server:
-| Route | Description |
-|---------------|-----------------------------------------------------------------------------|
-| `/` | Loads the profile page for the default Discord user defined in `.env` (`LANYARD_USER_ID`) |
-| `/[id]` | Loads the profile page for a specific Discord user ID passed in the URL |
+| Route | Description |
+|---------|-----------------------------------------------------------------------------|
+| `/` | Loads the profile page for the default Discord user defined in `.env` (`LANYARD_USER_ID`) |
+| `/[id]` | Loads the profile page for a specific Discord user ID passed in the URL |
> Example: `https://creations.works/209830981060788225` shows the profile of that specific user.
diff --git a/config/environment.ts b/config/environment.ts
index a7344f9..4d48b88 100644
--- a/config/environment.ts
+++ b/config/environment.ts
@@ -17,3 +17,6 @@ export const lanyardConfig: LanyardConfig = {
export const badgeApi: string | null = process.env.BADGE_API_URL || null;
export const steamGridDbKey: string | undefined =
process.env.STEAMGRIDDB_API_KEY;
+
+export const plausibleScript: string | null =
+ process.env.PLAUSIBLE_SCRIPT_HTML?.trim() || null;
diff --git a/src/routes/[id].ts b/src/routes/[id].ts
index 13b4920..55fe2e8 100644
--- a/src/routes/[id].ts
+++ b/src/routes/[id].ts
@@ -1,5 +1,5 @@
import { resolve } from "node:path";
-import { badgeApi, lanyardConfig } from "@config/environment";
+import { badgeApi, lanyardConfig, plausibleScript } from "@config/environment";
import { file } from "bun";
const routeDef: RouteDef = {
@@ -23,6 +23,10 @@ async function handler(request: ExtendedRequest): Promise {
head.setAttribute("data-user-id", id || lanyardConfig.userId);
head.setAttribute("data-instance-uri", instance);
head.setAttribute("data-badge-url", badgeApi || "");
+
+ if (plausibleScript) {
+ head.append(plausibleScript, { html: true });
+ }
},
})
.transform(await bunFile.text());