Skip to content

Commit 4542cb7

Browse files
committed
Add my gtag
1 parent 7bbd73d commit 4542cb7

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/analytics/google-analytics.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Google Analytics (gtag) loader
2+
3+
(function () {
4+
const GA_ID = 'G-LF96D9G25P'; // Update this with your Google Analytics ID
5+
6+
const script = document.createElement('script');
7+
script.async = true;
8+
script.src = `https://www.googletagmanager.com/gtag/js?id=${GA_ID}`;
9+
document.head.appendChild(script);
10+
11+
window.dataLayer = window.dataLayer || [];
12+
function gtag() {
13+
window.dataLayer.push(arguments);
14+
}
15+
window.gtag = gtag;
16+
17+
gtag('js', new Date());
18+
gtag('config', GA_ID);
19+
})();

src/layouts/Layout.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const isAbout = pageTitle === 'About';
4545
document.documentElement.classList.remove('dark');
4646
}
4747
</script>
48+
<script
49+
is:inline
50+
type='text/partytown'
51+
src='../analytics/google-analytics.js'></script>
4852
</head>
4953
<body class='flex min-h-screen flex-col pt-16 bg-white dark:bg-dark-bg'>
5054
<Header pageTitle={pageTitle} />

0 commit comments

Comments
 (0)