Skip to content

Commit dba053a

Browse files
authored
feat: add google analytics (#2)
1 parent dab9b00 commit dba053a

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

astro.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ import remarkBlockContainers from 'remark-block-containers';
1212
import astroExpressiveCode from 'astro-expressive-code';
1313
import rehypeFigure from 'rehype-figure';
1414
import remarkFigureCaption from "@microflash/remark-figure-caption";
15+
import partytown from '@astrojs/partytown'
1516

1617
import { remarkModifiedTime } from './plugins/remark-modified-time';
1718
import { remarkReadingTime } from './plugins/remark-reading-time';
1819
import slateConfig from './slate.config';
1920

2021
function computedIntegrations() {
21-
const result = [astroExpressiveCode(), mdx(), react(), sitemap(slateConfig.sitemap)];
22+
const result = [astroExpressiveCode(), mdx(), react(), sitemap(slateConfig.sitemap), partytown({
23+
config: {
24+
forward: ["dataLayer.push"],
25+
},
26+
})];
2227

2328
return result;
2429
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"@astrojs/check": "^0.9.4",
2525
"@astrojs/mdx": "^4.0.8",
26+
"@astrojs/partytown": "^2.1.4",
2627
"@astrojs/react": "^4.2.0",
2728
"@astrojs/rss": "^4.0.11",
2829
"@astrojs/sitemap": "^3.2.1",

pnpm-lock.yaml

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

src/components/layouts/HeadMeta.astro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ const { title, description, image } = Astro.props;
3737
<meta property="twitter:description" content={description} />
3838
<meta property="twitter:image" content={new URL(image, Astro.url)} />
3939

40+
<!-- Google Analytics -->
41+
<script is:inline type="text/partytown" async src="https://www.googletagmanager.com/gtag/js?id=G-1CHQV4JH2Z"></script>
42+
<script is:inline type="text/partytown">
43+
window.dataLayer = window.dataLayer || [];
44+
function gtag(...args){dataLayer.push(args);}
45+
gtag('js', new Date());
46+
47+
gtag('config', 'G-1CHQV4JH2Z');
48+
</script>
49+
4050
<link
4151
rel="alternate"
4252
type="application/rss+xml"

0 commit comments

Comments
 (0)