- {PlatformFeatures[PlatformFeature.ASSISTANTS] && }
+
+ {PlatformFeatures[PlatformFeature.ASSISTANTS] && }
+
\n?/g, '')
+ }
+
+ const gaScripts = `
+
+ `
+
+ return html.replace('', gaScripts)
+ },
+ }
+}
+
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
@@ -24,6 +59,7 @@ export default defineConfig(({ mode }) => {
nodePolyfills({
include: ['path'],
}),
+ injectGoogleAnalytics(env.GA_MEASUREMENT_ID),
],
resolve: {
alias: {
diff --git a/web-app/vite.config.web.ts b/web-app/vite.config.web.ts
index 0f96b2213..4db29761d 100644
--- a/web-app/vite.config.web.ts
+++ b/web-app/vite.config.web.ts
@@ -1,9 +1,46 @@
-import { defineConfig } from 'vite'
+import { defineConfig, Plugin } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+// Plugin to inject GA scripts in HTML
+function injectGoogleAnalytics(): Plugin {
+ return {
+ name: 'inject-google-analytics',
+ transformIndexHtml(html) {
+ const gaMeasurementId = process.env.GA_MEASUREMENT_ID
+
+ // Only inject GA scripts if GA_MEASUREMENT_ID is set
+ if (!gaMeasurementId) {
+ // Remove placeholder if no GA ID
+ return html.replace(/\s*\n?/g, '')
+ }
+
+ const gaScripts = `
+
+ `
+
+ return html.replace('', gaScripts)
+ },
+ }
+}
+
export default defineConfig({
plugins: [
TanStackRouterVite({
@@ -13,6 +50,7 @@ export default defineConfig({
}),
react(),
tailwindcss(),
+ injectGoogleAnalytics(),
],
build: {
outDir: './dist-web',