-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.js
61 lines (55 loc) 路 2.02 KB
/
gatsby-ssr.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from "react";
export { wrapRootElement } from "./src/apollo/wrapper";
const MagicScriptTag = () => {
let codeToRunOnClient = `
(function() {
function getInitialColorMode() {
const persistedColorPreference = window.localStorage.getItem('color-mode');
const hasPersistedPreference = typeof persistedColorPreference === 'string';
// If the user has explicitly chosen light or dark,
// let's use it. Otherwise, this value will be null.
if (hasPersistedPreference) {
return persistedColorPreference;
}
// If they haven't been explicit, let's check the media
// query
const mql = window.matchMedia('(prefers-color-scheme: dark)');
const hasMediaQueryPreference = typeof mql.matches === 'boolean';
if (hasMediaQueryPreference) {
return mql.matches ? 'dark' : 'light';
}
// If they are using a browser/OS that doesn't support
// color themes, let's default to 'light'.
return 'light';
}
const colorMode = getInitialColorMode();
const root = document.documentElement;
root.style.setProperty('--initial-color-mode', colorMode);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-835368541');
gtag('event', 'conversion', {'send_to': 'AW-835368541/MEc3CL2zvr8DEN3sqo4D'});
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-NWDHZYYH85');
})()`;
// eslint-disable-next-line react/no-danger
return (
<>
<script dangerouslySetInnerHTML={{ __html: codeToRunOnClient }} />
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-NWDHZYYH85"
></script>
<script
async
src="https://www.googletagmanager.com/gtag/js?id=AW-835368541"
></script>
</>
);
};
export const onRenderBody = ({ setPreBodyComponents }) => {
setPreBodyComponents(<MagicScriptTag />);
};