Add Google Analytics

This commit is contained in:
prototypa
2022-09-11 07:01:08 -04:00
parent f061df509c
commit 45552104b2
3 changed files with 3 additions and 18 deletions

View File

@ -19,6 +19,7 @@
"@astrojs/rss": "^1.0.0", "@astrojs/rss": "^1.0.0",
"@astrojs/sitemap": "^1.0.0", "@astrojs/sitemap": "^1.0.0",
"@astrojs/tailwind": "^1.0.0", "@astrojs/tailwind": "^1.0.0",
"@astrolib/google-analytics": "^0.2.1",
"@astrolib/seo": "^0.2.0", "@astrolib/seo": "^0.2.0",
"@fontsource/inter": "^4.5.12", "@fontsource/inter": "^4.5.12",
"@tailwindcss/typography": "^0.5.4", "@tailwindcss/typography": "^0.5.4",

View File

@ -1,16 +0,0 @@
---
const { id = 'G-XXXXXXXXXX', partytown = false } = Astro.props;
const attrs = partytown ? { type: 'text/partytown' } : {};
---
<script is:inline async src={`https://www.googletagmanager.com/gtag/js?id=${id}`} {...attrs}></script>
<script is:inline define:vars={{ id }} {...attrs}>
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', id);
</script>

View File

@ -1,9 +1,9 @@
--- ---
import { AstroSeo } from "@astrolib/seo" import { AstroSeo } from "@astrolib/seo"
import { GoogleAnalytics } from "@astrolib/google-analytics"
import { getImage } from '@astrojs/image'; import { getImage } from '@astrojs/image';
import { getRelativeUrlByFilePath } from '~/utils/directories'; import { getRelativeUrlByFilePath } from '~/utils/directories';
import GoogleAnalytics from '~/components/core/GoogleAnalytics.astro';
import defaultImageSrc from '~/assets/images/default.png'; import defaultImageSrc from '~/assets/images/default.png';
import { SITE } from '~/config.mjs'; import { SITE } from '~/config.mjs';
@ -74,6 +74,6 @@ const image =
{SITE.googleSiteVerificationId && <meta name="google-site-verification" content={SITE.googleSiteVerificationId} />} {SITE.googleSiteVerificationId && <meta name="google-site-verification" content={SITE.googleSiteVerificationId} />}
<!-- Google Analytics --> <!-- Google Analytics -->
{SITE.googleAnalyticsId && <GoogleAnalytics id={SITE.googleAnalyticsId} partytown={true} />} {SITE.googleAnalyticsId && <GoogleAnalytics id={String(SITE.googleAnalyticsId)} partytown={true} />}
<ExtraMetaTags /> <ExtraMetaTags />