Skip to content

Commit e739cb5

Browse files
fix google import
1 parent 99b13d5 commit e739cb5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/components/analytics/Clarity.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import clarityScript from "./clarity?url";
44
const isProd = import.meta.env.PROD as boolean;
55
---
66

7-
{!isProd && <script type="text/javascript" src={clarityScript} is:inline />}
7+
{isProd && <script type="text/javascript" src={clarityScript} is:inline />}

src/components/analytics/Google.astro

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
import google from "./google?url";
3+
//@ts-ignore
4+
const isProd = import.meta.env.PROD as boolean;
5+
---
6+
7+
{
8+
isProd && (
9+
<>
10+
<script
11+
is:inline
12+
type="text/partytown"
13+
src={`https://www.googletagmanager.com/gtag/js?id=G-Z2X2PB0P4E`}
14+
/>
15+
<script is:inline type="text/partytown" src={google} />
16+
</>
17+
)
18+
}

src/components/analytics/google.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
window.dataLayer = window.dataLayer || [];
2+
function gtag() {
3+
window.dataLayer.push(arguments);
4+
}
5+
gtag("js", new Date());
6+
gtag("config", "G-Z2X2PB0P4E");

src/layouts/BaseLayout.astro

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
import FloatingLinks from "../components/FloatingLinks.astro";
33
import Footer from "../components/base/Footer.astro";
4-
import { GoogleAnalytics } from "@astrolib/analytics";
54
import "../styles/global.scss";
65
import { CookieBar } from "../components/base/CookieBar/CookieBar";
76
import Clarity from "../components/analytics/Clarity.astro";
7+
import Google from "../components/analytics/Google.astro";
88
99
const favSizes = [
1010
16, 32, 57, 60, 70, 72, 76, 96, 114, 120, 128, 144, 150, 152, 180, 192, 310, 384, 512,
@@ -53,7 +53,7 @@ const { url, title, description, featuredImage, imageWidth, imageHeight } = Astr
5353
}
5454
<link rel="icon" type="image/ico" href="/favicon/favicon.ico" />
5555
<link rel="sitemap" href="/sitemap-index.xml" />
56-
<GoogleAnalytics />
56+
<Google />
5757
</head>
5858
<body>
5959
<slot />

0 commit comments

Comments
 (0)