Google analytics integration.
Sentry.io integration. Vince integration. Region-scoped consent (denied-by-default in EU/EEA/UK/CH, granted elsewhere, DPDP-friendly notice)
This commit is contained in:
@@ -6,6 +6,12 @@ import {
|
||||
} from "@tanstack/react-router";
|
||||
import "./globals.css";
|
||||
import Providers from "./-providers";
|
||||
import { ConsentGate, PageViewTracker, WebVitalsReporter } from "./-analytics";
|
||||
import {
|
||||
consentDefaultsSnippet,
|
||||
ga4HeadScripts,
|
||||
PLAUSIBLE_DOMAIN,
|
||||
} from "@/lib/analytics";
|
||||
import { getAnnouncement } from "@/lib/content";
|
||||
|
||||
export const Route = createRootRoute({
|
||||
@@ -97,10 +103,36 @@ export const Route = createRootRoute({
|
||||
{ rel: "preload", as: "image", href: "/banners/banner-1.jpg" },
|
||||
{ rel: "preload", as: "image", href: "/logo/logo-white.svg" },
|
||||
],
|
||||
scripts: analyticsHeadScripts(),
|
||||
}),
|
||||
component: RootDocument,
|
||||
});
|
||||
|
||||
/**
|
||||
* Analytics tags, production-only (nothing loads in `npm run dev` or when the
|
||||
* corresponding env var is unset). Order matters:
|
||||
* 1. Consent Mode v2 regional defaults (must precede the gtag loader),
|
||||
* 2. GA4 gtag loader + config (cross-domain linked with shop.mozimo.in),
|
||||
* 3. first-party Vince/Plausible-protocol script, proxied at /stats.
|
||||
*/
|
||||
function analyticsHeadScripts() {
|
||||
if (!import.meta.env.PROD) return [];
|
||||
return [
|
||||
...(ga4HeadScripts().length
|
||||
? [{ children: consentDefaultsSnippet() }, ...ga4HeadScripts()]
|
||||
: []),
|
||||
...(PLAUSIBLE_DOMAIN
|
||||
? [
|
||||
{
|
||||
src: "/stats/js/script.js",
|
||||
defer: true,
|
||||
"data-domain": PLAUSIBLE_DOMAIN,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
}
|
||||
|
||||
function RootDocument() {
|
||||
return (
|
||||
<html lang="en">
|
||||
@@ -111,6 +143,10 @@ function RootDocument() {
|
||||
<Providers>
|
||||
<Outlet />
|
||||
</Providers>
|
||||
{/* analytics — client-only, render nothing */}
|
||||
<PageViewTracker />
|
||||
<WebVitalsReporter />
|
||||
<ConsentGate />
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user