add Google Analytics 4 (gtag.js) tracking
This commit is contained in:
@@ -13,6 +13,7 @@ const pageTitle = title || site.name;
|
||||
const ogUrl = canonical || Astro.url.toString();
|
||||
const year = new Date().getFullYear();
|
||||
const ads = site.ads;
|
||||
const analytics = site.analytics;
|
||||
---
|
||||
<!DOCTYPE html>
|
||||
<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.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&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;600&display=swap" rel="stylesheet" />
|
||||
|
||||
@@ -13,4 +13,7 @@ export const site = {
|
||||
bottom: '6973857406',
|
||||
},
|
||||
},
|
||||
analytics: {
|
||||
measurementId: 'G-1XG3LBRLWW',
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user