From bcc965655d063d657e563585ac3b5b8bcc275fcf Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Mon, 13 Jul 2026 10:08:58 +0200 Subject: [PATCH] Aggiunge integrazione Google Tag Manager attivabile via env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GTM viene caricato nel layout Base solo se la variabile GTM_ID è valorizzata. L'ID è letto a runtime da process.env (non inlinato a build-time), così si attiva/disattiva senza ricompilare. Con GTM_ID vuoto il sito non carica alcuno script Google. Co-Authored-By: Claude Opus 4.8 (1M context) --- .env.example | 4 ++++ src/layouts/Base.astro | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/.env.example b/.env.example index cf4b6c4..4f9c5cf 100644 --- a/.env.example +++ b/.env.example @@ -11,3 +11,7 @@ CONTACT_FROM=postmaster@insanitylab.it CONTACT_TO=info@insanitylab.it DB_PATH=data/insanitylab.db UPLOADS_DIR=uploads + +# Google Tag Manager: ID container preso da tagmanager.google.com (accanto al nome container). +# Formato GTM-XXXXXXX. Lascia vuoto per non caricare GTM (es. in locale/staging). +GTM_ID=GTM-XXXXXXX diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index e996187..fe779f3 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -19,10 +19,17 @@ const user = tok ? getSessionUser(getDb(), tok) : null; const canTags = !!user && (user.role === 'superuser' || user.role === 'admin'); const wantTags = Astro.cookies.get('showtags')?.value === '1' || Astro.url.searchParams.get('annotate') === '1'; const showTags = canTags && wantTags; + +// Google Tag Manager: l'ID container arriva da GTM_ID (.env), letto a runtime via process.env +// perché in SSR le PUBLIC_* di Vite verrebbero inlinate a build-time. Se vuoto GTM non carica. +const gtmId = process.env.GTM_ID; --- + {gtmId && ( + + {gtmId && ( +