mirror of
https://github.com/hanzoai/agency.git
synced 2026-10-26 05:24:32 +00:00
The head configured GA4 behind a gtag.js script tag, so a network that dropped Google's host held the load event hostage. Configure it inline and fetch gtag.js once the page has loaded, with a linker across the Hanzo domains a visit crosses, and the same GPC/DNT opt-out the site's own telemetry honors. The ID lived in both hanzo.yml and index.html. vite.config.ts now reads it from hanzo.yml into index.html. ScrollToTop sent its own page_view on every route change, on top of GA4's history listener, so each page counted twice. Drop it.
28 lines
753 B
TypeScript
28 lines
753 B
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react-swc";
|
|
import path from "path";
|
|
import { readFileSync } from "fs";
|
|
|
|
// The GA4 stream is stated once, in hanzo.yml; index.html names it as %GA%.
|
|
const GA = /googleAnalyticsId:\s*(G-[A-Z0-9]+)/.exec(
|
|
readFileSync(path.resolve(__dirname, "hanzo.yml"), "utf8"),
|
|
)?.[1];
|
|
if (!GA) throw new Error("hanzo.yml states no analytics.googleAnalyticsId");
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => ({
|
|
server: {
|
|
host: "::",
|
|
port: 8080,
|
|
},
|
|
plugins: [
|
|
react(),
|
|
{ name: "ga", transformIndexHtml: (html: string) => html.replaceAll("%GA%", GA) },
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
"@": path.resolve(__dirname, "./src"),
|
|
},
|
|
},
|
|
}));
|