Add Plausible analytics support with configurable domain and script URL
Made-with: Cursor
This commit is contained in:
@@ -5,6 +5,17 @@ import { ErrorBoundary } from "./ErrorBoundary";
|
||||
import { ToastProvider } from "./contexts/ToastContext";
|
||||
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");
|
||||
if (!rootEl) {
|
||||
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 {
|
||||
readonly VITE_API_URL: string;
|
||||
readonly VITE_PLAUSIBLE_DOMAIN: string;
|
||||
readonly VITE_PLAUSIBLE_SCRIPT_URL: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
Reference in New Issue
Block a user