Add Plausible analytics support with configurable domain and script URL
Made-with: Cursor
This commit is contained in:
@@ -4,3 +4,7 @@ VITE_API_URL=http://localhost:3001
|
|||||||
|
|
||||||
# Nostr relays for fetching user profile metadata (comma-separated)
|
# Nostr relays for fetching user profile metadata (comma-separated)
|
||||||
VITE_NOSTR_RELAYS=wss://relay.damus.io,wss://relay.nostr.band,wss://nos.lol
|
VITE_NOSTR_RELAYS=wss://relay.damus.io,wss://relay.nostr.band,wss://nos.lol
|
||||||
|
|
||||||
|
# Plausible analytics (optional; leave empty to disable)
|
||||||
|
VITE_PLAUSIBLE_DOMAIN=faucet.lnpulse.app
|
||||||
|
VITE_PLAUSIBLE_SCRIPT_URL=https://analytics.azzamo.net/js/script.js
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ import { ErrorBoundary } from "./ErrorBoundary";
|
|||||||
import { ToastProvider } from "./contexts/ToastContext";
|
import { ToastProvider } from "./contexts/ToastContext";
|
||||||
import "./styles/global.css";
|
import "./styles/global.css";
|
||||||
|
|
||||||
|
// Plausible analytics (injected in head when env vars are set)
|
||||||
|
const plausibleDomain = import.meta.env.VITE_PLAUSIBLE_DOMAIN as string | undefined;
|
||||||
|
const plausibleScriptUrl = import.meta.env.VITE_PLAUSIBLE_SCRIPT_URL as string | undefined;
|
||||||
|
if (plausibleDomain && plausibleScriptUrl) {
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.defer = true;
|
||||||
|
script.dataset.domain = plausibleDomain;
|
||||||
|
script.src = plausibleScriptUrl;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
const rootEl = document.getElementById("root");
|
const rootEl = document.getElementById("root");
|
||||||
if (!rootEl) {
|
if (!rootEl) {
|
||||||
document.body.innerHTML = "<p>Root element #root not found.</p>";
|
document.body.innerHTML = "<p>Root element #root not found.</p>";
|
||||||
|
|||||||
2
frontend/src/vite-env.d.ts
vendored
2
frontend/src/vite-env.d.ts
vendored
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_API_URL: string;
|
readonly VITE_API_URL: string;
|
||||||
|
readonly VITE_PLAUSIBLE_DOMAIN: string;
|
||||||
|
readonly VITE_PLAUSIBLE_SCRIPT_URL: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|||||||
Reference in New Issue
Block a user