Google Analytics and fixed astro config site

This commit is contained in:
Sammy Shear 2024-03-22 22:14:42 -04:00
parent b3b8849ed2
commit 0cb5d90fa2
No known key found for this signature in database
GPG Key ID: DDBE1CD1708599BD
5 changed files with 59 additions and 2 deletions

View File

@ -5,10 +5,19 @@ import robotsTxt from "astro-robots-txt";
import sitemap from "@astrojs/sitemap";
import compressor from "astro-compressor";
import partytown from "@astrojs/partytown";
// https://astro.build/config
export default defineConfig({
site: "https://localhost:4321",
integrations: [tailwind(), react(), robotsTxt(), sitemap(), compressor()],
site: "https://sshear.dev",
integrations: [
tailwind(),
react(),
robotsTxt(),
sitemap(),
compressor(),
partytown({ config: { forward: ["dataLayer.push"] } })
],
markdown: {
shikiConfig: {
themes: {

View File

@ -12,6 +12,7 @@
},
"dependencies": {
"@astrojs/check": "^0.5.9",
"@astrojs/partytown": "^2.0.4",
"@astrojs/react": "^3.1.0",
"@astrojs/sitemap": "^3.1.1",
"@astrojs/tailwind": "^5.1.0",

View File

@ -8,6 +8,9 @@ dependencies:
'@astrojs/check':
specifier: ^0.5.9
version: 0.5.9(prettier-plugin-astro@0.13.0)(prettier@3.2.5)(typescript@5.4.2)
'@astrojs/partytown':
specifier: ^2.0.4
version: 2.0.4
'@astrojs/react':
specifier: ^3.1.0
version: 3.1.0(@types/react-dom@18.2.22)(@types/react@18.2.67)(react-dom@18.2.0)(react@18.2.0)(vite@5.1.6)
@ -163,6 +166,13 @@ packages:
- supports-color
dev: false
/@astrojs/partytown@2.0.4:
resolution: {integrity: sha512-yC1smFLOBn7CWNAzaigXAr4bSJSgRJYF4g9jDuSR0NbShLd1SVUpRm9QOmOIrfSFGh2YtZEW8gnwvI5SZw+WmA==}
dependencies:
'@builder.io/partytown': 0.8.2
mrmime: 1.0.1
dev: false
/@astrojs/prism@3.0.0:
resolution: {integrity: sha512-g61lZupWq1bYbcBnYZqdjndShr/J3l/oFobBKPA3+qMat146zce3nz2kdO4giGbhYDt4gYdhmoBz0vZJ4sIurQ==}
engines: {node: '>=18.14.1'}
@ -474,6 +484,12 @@ packages:
to-fast-properties: 2.0.0
dev: false
/@builder.io/partytown@0.8.2:
resolution: {integrity: sha512-WKGE+SO0qUGirW8J+xOWkHeCkfFEoPPvHnFkcdMl+MY3kDbAcTwjZCzjg27JCvoD0h8fH47FR7DSIss0/S5lyg==}
engines: {node: '>=18.0.0'}
hasBin: true
dev: false
/@catppuccin/tailwindcss@0.1.6(tailwindcss@3.4.1):
resolution: {integrity: sha512-V+Y0AwZ5SSyvOVAcDl7Ng30xy+m82OKnEJ+9+kcZZ7lRyXuZrAb2GScdq9XR3v+ggt8qiZ/G4TvaC9cJ88AAXA==}
peerDependencies:
@ -2813,6 +2829,11 @@ packages:
dev: false
optional: true
/mrmime@1.0.1:
resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==}
engines: {node: '>=10'}
dev: false
/ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: false

View File

@ -0,0 +1,23 @@
---
type Props = { measurementId: string }
const props = Astro.props as Props
const measurementId = props.measurementId
---
<script
type='text/partytown'
src={`https://www.googletagmanager.com/gtag/js?id=${measurementId}`}></script>
<script
type='text/partytown'
data-ga-measurement-id={measurementId}
id='ga-init'
>
const measurementId = document
.getElementById('ga-init')
.getAttribute('data-ga-measurement-id')
window.dataLayer = window.dataLayer || []
function gtag() {
dataLayer.push(arguments) // eslint-disable-line
}
gtag('js', new Date())
gtag('config', measurementId)
</script>

View File

@ -1,5 +1,7 @@
---
import { SITE } from "../config";
import GoogleAnalytics from "../components/GoogleAnalytics.astro";
export interface Props {
title?: string;
author?: string;
@ -16,6 +18,7 @@ const {
<html lang="en">
<head>
<meta charset="utf-8" />
<GoogleAnalytics measurementId="G-LBCCNW1R6M" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />