Skip to content

Commit 6eacec6

Browse files
authored
feat: Added Google Analytics (#22)
* feat: Added Google Analytics * chore: enables analytics storage
1 parent c00dfbb commit 6eacec6

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

astro.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import sitemap from '@astrojs/sitemap'
55
import tailwindcss from '@tailwindcss/vite'
66
import { defineConfig, fontProviders } from 'astro/config'
77
import expressiveCode from 'astro-expressive-code'
8+
import partytown from '@astrojs/partytown'
89

910
// https://astro.build/config
1011
export default defineConfig({
1112
site: 'https://nodejsdesignpatterns.com',
12-
integrations: [react(), expressiveCode(), sitemap()],
13+
integrations: [
14+
react(),
15+
expressiveCode(),
16+
sitemap(),
17+
partytown({ config: { forward: ['dataLayer.push'] } }),
18+
],
1319
vite: {
1420
plugins: [tailwindcss()],
1521
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"typecheck": "tsc --noEmit"
1515
},
1616
"dependencies": {
17+
"@astrojs/partytown": "^2.1.4",
1718
"@astrojs/react": "^4.3.1",
1819
"@astrojs/sitemap": "^3.6.0",
1920
"@lucide/astro": "^0.522.0",

pnpm-lock.yaml

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

src/Layout.astro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ const {
140140
<Font cssVariable="--font-base-sans" preload />
141141
<Font cssVariable="--font-base-serif" preload />
142142
<Font cssVariable="--font-base-mono" preload />
143+
144+
<!-- Google tag (gtag.js) -->
145+
<script
146+
is:inline
147+
type="text/partytown"
148+
src="https://www.googletagmanager.com/gtag/js?id=G-NFE37ZH2W3"></script>
149+
<script is:inline type="text/partytown">
150+
window.dataLayer = window.dataLayer || []
151+
function gtag() {
152+
// eslint-disable-next-line no-undef
153+
dataLayer.push(arguments)
154+
}
155+
gtag('js', new Date())
156+
// Disable all tracking by default
157+
gtag('consent', 'default', {
158+
ad_storage: 'denied',
159+
ad_user_data: 'denied',
160+
ad_personalization: 'denied',
161+
// analytics_storage: 'denied',
162+
})
163+
gtag('config', 'G-NFE37ZH2W3')
164+
</script>
143165
</head>
144166
<body
145167
class="antialiased transition-colors duration-300 bg-base-100 text-base-content"

0 commit comments

Comments
 (0)