add Google Analytics 4 (gtag.js) tracking
Measurement ID G-2WWKKGDL6H wired via site.analytics.measurementId. Layout conditionally injects the gtag.js loader + dataLayer init + config call when analytics.measurementId is set, mirroring the AdSense conditional pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ const pageTitle = title || site.name;
|
|||||||
const ogUrl = canonical || Astro.url.toString();
|
const ogUrl = canonical || Astro.url.toString();
|
||||||
const year = new Date().getFullYear();
|
const year = new Date().getFullYear();
|
||||||
const ads = site.ads;
|
const ads = site.ads;
|
||||||
|
const analytics = site.analytics;
|
||||||
---
|
---
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -53,6 +54,18 @@ const ads = site.ads;
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{analytics?.measurementId && (
|
||||||
|
<>
|
||||||
|
<script async src={`https://www.googletagmanager.com/gtag/js?id=${analytics.measurementId}`} />
|
||||||
|
<script set:html={`
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', '${analytics.measurementId}');
|
||||||
|
`} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,800;9..144,900&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=VT323&family=Major+Mono+Display&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,800;9..144,900&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=VT323&family=Major+Mono+Display&display=swap" rel="stylesheet" />
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ export const site = {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
publisherId: '9763775565109295',
|
publisherId: '9763775565109295',
|
||||||
},
|
},
|
||||||
|
analytics: {
|
||||||
|
measurementId: 'G-2WWKKGDL6H',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user