Skip to content

Commit 038951a

Browse files
feat: adding Google Analytics (#18)
1 parent faa6a32 commit 038951a

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

astro.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'astro/config';
22
import tailwind from '@astrojs/tailwind';
33
import react from '@astrojs/react'; // Add this line
44
import mdx from '@astrojs/mdx';
5+
import partytown from '@astrojs/partytown';
56

67
// Determine site URL based on environment
78
const getSiteURL = () => {
@@ -30,5 +31,10 @@ export default defineConfig({
3031
tailwind(),
3132
react(),
3233
mdx(),
34+
partytown({
35+
config: {
36+
forward: ["dataLayer.push"],
37+
},
38+
}),
3339
],
3440
});

package-lock.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@astrojs/db": "0.14.10",
1515
"@astrojs/mdx": "4.2.3",
1616
"@astrojs/node": "9.1.3",
17+
"@astrojs/partytown": "2.1.4",
1718
"@astrojs/react": "4.2.3",
1819
"@astrojs/rss": "3.0.0",
1920
"@astrojs/sitemap": "^3.0.0",

src/layouts/Layout.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ const { title, description = "A minimalist personal blog" } = Astro.props;
2727
<link rel="preconnect" href="https://fonts.googleapis.com">
2828
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
2929
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
30+
<!-- Google tag (gtag.js) -->
31+
<script type="text/partytown" async src="https://www.googletagmanager.com/gtag/js?id=G-PFZ9KVEQPD"></script>
32+
<script type="text/partytown">
33+
window.dataLayer = window.dataLayer || [];
34+
function gtag(){dataLayer.push(arguments);}
35+
gtag('js', new Date());
36+
37+
gtag('config', 'G-PFZ9KVEQPD');
38+
</script>
3039
</head>
3140
<body class="bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 min-h-screen flex flex-col">
3241
<!-- Page transition overlay - for smooth transitions between pages -->

0 commit comments

Comments
 (0)