-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.tsx
41 lines (39 loc) · 1.3 KB
/
gatsby-ssr.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from "react";
import { GatsbySSR, withPrefix } from "gatsby";
import { Partytown } from "@builder.io/partytown/react";
// You might prefer to add these as an env vars
const ORIGIN = "https://www.googletagmanager.com";
const GATSBY_GA_MEASUREMENT_ID = "G-2XYKVWN08T";
export const onRenderBody: GatsbySSR["onRenderBody"] = ({
setHeadComponents,
}) => {
setHeadComponents([
<link
key="icons-preload"
rel="preload"
href={withPrefix(`/icons.svg`)}
as="image"
type="image/svg+xml"
/>,
...(process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test"
? [
<Partytown key="partytown" forward={["gtag"]} />,
<script
key="google-analytics"
type="text/partytown"
src={`${ORIGIN}/gtag/js?id=${GATSBY_GA_MEASUREMENT_ID}`}
/>,
<script
key="google-analytics-config"
type="text/partytown"
dangerouslySetInnerHTML={{
__html: `window.dataLayer = window.dataLayer || [];
window.gtag = function gtag(){ window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GATSBY_GA_MEASUREMENT_ID}', { send_page_view: false })`,
}}
/>,
]
: []),
]);
};