From 04b2fa02a9ce323170f482cf940f9fcb7ffcbf34 Mon Sep 17 00:00:00 2001 From: qingyu31 Date: Thu, 21 Nov 2024 21:38:53 +0800 Subject: [PATCH] Google Analytics --- src/layouts/Layout.astro | 12 ++++++++++++ src/types/config.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index af46e2c54..8536eda02 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -71,6 +71,8 @@ const bannerOffsetByPosition = { } const bannerOffset = bannerOffsetByPosition[siteConfig.banner.position || 'center'] + +const gtagId = siteConfig.googleAnalytics? siteConfig.googleAnalytics.id : '' --- @@ -78,6 +80,16 @@ const bannerOffset = data-overlayscrollbars-initialize > + {gtagId.length > 0 && + + + } {pageTitle} diff --git a/src/types/config.ts b/src/types/config.ts index 67e5f2596..adb8f8f0d 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -24,6 +24,9 @@ export type SiteConfig = { enable: boolean depth: 1 | 2 | 3 } + googleAnalytics?: { + id: string + } favicon: Favicon[] }