Aggiunge integrazione Google Tag Manager attivabile via env
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) <noreply@anthropic.com>
This commit is contained in:
@@ -11,3 +11,7 @@ CONTACT_FROM=postmaster@insanitylab.it
|
|||||||
CONTACT_TO=info@insanitylab.it
|
CONTACT_TO=info@insanitylab.it
|
||||||
DB_PATH=data/insanitylab.db
|
DB_PATH=data/insanitylab.db
|
||||||
UPLOADS_DIR=uploads
|
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
|
||||||
|
|||||||
@@ -19,10 +19,17 @@ const user = tok ? getSessionUser(getDb(), tok) : null;
|
|||||||
const canTags = !!user && (user.role === 'superuser' || user.role === 'admin');
|
const canTags = !!user && (user.role === 'superuser' || user.role === 'admin');
|
||||||
const wantTags = Astro.cookies.get('showtags')?.value === '1' || Astro.url.searchParams.get('annotate') === '1';
|
const wantTags = Astro.cookies.get('showtags')?.value === '1' || Astro.url.searchParams.get('annotate') === '1';
|
||||||
const showTags = canTags && wantTags;
|
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;
|
||||||
---
|
---
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="it">
|
<html lang="it">
|
||||||
<head>
|
<head>
|
||||||
|
{gtmId && (
|
||||||
|
<script is:inline set:html={`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${gtmId}');`} />
|
||||||
|
)}
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>{title} — InsanityLab</title>
|
<title>{title} — InsanityLab</title>
|
||||||
@@ -36,6 +43,9 @@ const showTags = canTags && wantTags;
|
|||||||
<script is:inline>document.documentElement.classList.add('js');</script>
|
<script is:inline>document.documentElement.classList.add('js');</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
{gtmId && (
|
||||||
|
<noscript set:html={`<iframe src="https://www.googletagmanager.com/ns.html?id=${gtmId}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`} />
|
||||||
|
)}
|
||||||
<Header user={user} showTags={showTags} canTags={canTags} />
|
<Header user={user} showTags={showTags} canTags={canTags} />
|
||||||
<main><slot /></main>
|
<main><slot /></main>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
Reference in New Issue
Block a user