add plausible support
All checks were successful
Code quality checks / biome (push) Successful in 8s
All checks were successful
Code quality checks / biome (push) Successful in 8s
This commit is contained in:
parent
dbe894a568
commit
167d989600
4 changed files with 38 additions and 6 deletions
|
@ -14,3 +14,6 @@ BADGE_API_URL=http://localhost:8081
|
||||||
|
|
||||||
# https://www.steamgriddb.com/api/v2, if you want games to have images
|
# https://www.steamgriddb.com/api/v2, if you want games to have images
|
||||||
STEAMGRIDDB_API_KEY=steamgrid_api_key
|
STEAMGRIDDB_API_KEY=steamgrid_api_key
|
||||||
|
|
||||||
|
# https://plausible.io
|
||||||
|
PLAUSIBLE_SCRIPT_HTML=''
|
||||||
|
|
26
README.md
26
README.md
|
@ -29,7 +29,7 @@ https://git.creations.works/creations/badgeAPI
|
||||||
|
|
||||||
### 4. SteamGridDB
|
### 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
|
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 `<script>` tag(s) to inject into the `<head>` for analytics |
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```env
|
||||||
|
PLAUSIBLE_SCRIPT_HTML='<script defer data-domain="example.com" src="https://plausible.example.com/js/script.js"></script><script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>'
|
||||||
|
```
|
||||||
|
|
||||||
|
- 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
|
## Docker Support
|
||||||
|
|
||||||
### Build & Start with Docker Compose
|
### Build & Start with Docker Compose
|
||||||
|
@ -104,7 +126,7 @@ Make sure the `.env` file is configured correctly before starting the container.
|
||||||
These are the main public routes exposed by the server:
|
These are the main public routes exposed by the server:
|
||||||
|
|
||||||
| Route | Description |
|
| Route | Description |
|
||||||
|---------------|-----------------------------------------------------------------------------|
|
|---------|-----------------------------------------------------------------------------|
|
||||||
| `/` | Loads the profile page for the default Discord user defined in `.env` (`LANYARD_USER_ID`) |
|
| `/` | 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 |
|
| `/[id]` | Loads the profile page for a specific Discord user ID passed in the URL |
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,6 @@ export const lanyardConfig: LanyardConfig = {
|
||||||
export const badgeApi: string | null = process.env.BADGE_API_URL || null;
|
export const badgeApi: string | null = process.env.BADGE_API_URL || null;
|
||||||
export const steamGridDbKey: string | undefined =
|
export const steamGridDbKey: string | undefined =
|
||||||
process.env.STEAMGRIDDB_API_KEY;
|
process.env.STEAMGRIDDB_API_KEY;
|
||||||
|
|
||||||
|
export const plausibleScript: string | null =
|
||||||
|
process.env.PLAUSIBLE_SCRIPT_HTML?.trim() || null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { badgeApi, lanyardConfig } from "@config/environment";
|
import { badgeApi, lanyardConfig, plausibleScript } from "@config/environment";
|
||||||
import { file } from "bun";
|
import { file } from "bun";
|
||||||
|
|
||||||
const routeDef: RouteDef = {
|
const routeDef: RouteDef = {
|
||||||
|
@ -23,6 +23,10 @@ async function handler(request: ExtendedRequest): Promise<Response> {
|
||||||
head.setAttribute("data-user-id", id || lanyardConfig.userId);
|
head.setAttribute("data-user-id", id || lanyardConfig.userId);
|
||||||
head.setAttribute("data-instance-uri", instance);
|
head.setAttribute("data-instance-uri", instance);
|
||||||
head.setAttribute("data-badge-url", badgeApi || "");
|
head.setAttribute("data-badge-url", badgeApi || "");
|
||||||
|
|
||||||
|
if (plausibleScript) {
|
||||||
|
head.append(plausibleScript, { html: true });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.transform(await bunFile.text());
|
.transform(await bunFile.text());
|
||||||
|
|
Loading…
Add table
Reference in a new issue