Skip to content

Commit 30bc01f

Browse files
author
sucongcong
committed
deat:添加 Google Analytics 追踪分析
1 parent e297ae0 commit 30bc01f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/components/BaseHead.astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url
6161
<meta content={description} property="twitter:description" />
6262
<meta content={socialImageURL} property="twitter:image" />
6363

64+
<!-- Google tag (gtag.js) -->
65+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MJYKGPVKY1"></script>
66+
<script>
67+
window.dataLayer = window.dataLayer || [];
68+
function gtag() {
69+
dataLayer.push(arguments);
70+
}
71+
gtag("js", new Date());
72+
73+
gtag("config", "G-MJYKGPVKY1");
74+
</script>
75+
6476
{/* Sitemap */}
6577
<link href="/sitemap-index.xml" rel="sitemap" />
6678

src/layouts/Base.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ThemeProvider from "@/components/ThemeProvider.astro";
77
import Footer from "@/components/layout/Footer.astro";
88
import Header from "@/components/layout/Header.astro";
99
import { siteConfig } from "@/site-config";
10-
import Analytics from '@vercel/analytics/astro'
10+
import Analytics from "@vercel/analytics/astro";
1111
interface Props {
1212
meta: SiteMeta;
1313
}
@@ -20,7 +20,7 @@ const {
2020
<html lang={siteConfig.lang}>
2121
<head>
2222
<BaseHead articleDate={articleDate} description={description} ogImage={ogImage} title={title} />
23-
<link rel="sitemap" href="/sitemap-index.xml" />
23+
<link href="/sitemap-index.xml" rel="sitemap" />
2424
</head>
2525
<body>
2626
<ThemeProvider />
@@ -30,6 +30,6 @@ const {
3030
<slot />
3131
</main>
3232
<Footer />
33-
<Analytics />
33+
<Analytics />
3434
</body>
3535
</html>

0 commit comments

Comments
 (0)