fix: google analytics only on production

This commit is contained in:
2026-10-04 10:51:53 +05:00
parent 1db83d12ff
commit e1fc11cb54
7 changed files with 26 additions and 20 deletions
-14
View File
@@ -4,20 +4,6 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="text-scale" content="scale" />
<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-MEQJ7JHRQQ"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-MEQJ7JHRQQ");
</script>
<script>
(() => {
try {
+11
View File
@@ -31,6 +31,10 @@
let crumb = $derived(toCrumb(page.url.pathname));
// GA подключается только в production-деплое: флаг выставляется в
// deploy-workflow, локальные и preview-сборки тег не получают.
const gaEnabled = import.meta.env.PUBLIC_GA_ENABLED === "true";
function toCrumb(path: string): string {
if (path === "/") return "/ " + t("header.home");
if (path === "/list-tools") return "/ " + t("header.catalog");
@@ -46,6 +50,13 @@
<svelte:head>
<link rel="icon" href={`${resolve("/")}favicon.svg`} />
{#if gaEnabled}
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-MEQJ7JHRQQ"
></script>
<script src={`${resolve("/")}ga.js`}></script>
{/if}
</svelte:head>
<main class="preview-root" data-theme={theme}>
+6
View File
@@ -0,0 +1,6 @@
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-MEQJ7JHRQQ");
+2
View File
@@ -11,6 +11,8 @@ const base: "" | `/${string}` =
: (`/${rawBase.replace(/^\/+/, "").replace(/\/+$/, "")}` as `/${string}`);
export default defineConfig({
// PUBLIC_* попадают в import.meta.env — флаги окружения вроде GA.
envPrefix: ["VITE_", "PUBLIC_"],
ssr: {
noExternal: ["@lucide/svelte"],
},