mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
fix: google analytics only on production
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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}>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag() {
|
||||
window.dataLayer.push(arguments);
|
||||
}
|
||||
gtag("js", new Date());
|
||||
gtag("config", "G-MEQJ7JHRQQ");
|
||||
@@ -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"],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user