-
Notifications
You must be signed in to change notification settings - Fork 5
/
gatsby-ssr.tsx
89 lines (84 loc) · 2.64 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react';
import { GA_ANALYTICS_ENDPOINT, GA_MEASUREMENT_ID, GA_ORIGIN } from './shared';
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/
*/
/**
* @type {import('gatsby').GatsbySSR['onRenderBody']}
*/
export const onRenderBody = ({ setHtmlAttributes, setHeadComponents }) => {
const googleAnalyticsHTML = `
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
// Default consent settings and tell it to wait a little bit for an wait
// for an update that will be coming from the banner module
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'security_storage': 'denied',
'wait_for_update': 500,
});
// Start up gtag
gtag('js', new Date());
gtag('config', '${GA_MEASUREMENT_ID}');
`;
setHtmlAttributes({ lang: 'en' });
setHeadComponents([
<link
rel="dns-prefetch"
key="dns-prefetch-google-gtag"
href={GA_ORIGIN}
/>,
<link rel="preconnect" key="preconnect-google-gtag" href={GA_ORIGIN} />,
<link
rel="dns-prefetch"
key="dns-prefetch-google-analytics"
href={GA_ANALYTICS_ENDPOINT}
/>,
<link
rel="preconnect"
key="preconnect-google-analytics"
href={GA_ANALYTICS_ENDPOINT}
/>,
<script
key="google-analytics-config"
dangerouslySetInnerHTML={{
__html: googleAnalyticsHTML,
}}
/>,
<script
key="google-analytics-loader"
async
src={`${GA_ORIGIN}/gtag/js?id=${GA_MEASUREMENT_ID}`}
/>,
<link
key="consent-cookiefirst"
rel="preconnect"
href="//consent.cookiefirst.com"
/>,
<link
key="edge-cookiefirst"
rel="dns-prefetch"
href="//edge.cookiefirst.com"
/>,
<link
key="api-cookiefirst"
rel="dns-prefetch"
href="//api.cookiefirst.com"
/>,
<script
key="script-cookiefirst"
id="CookieFirst"
async
src="https://consent.cookiefirst.com/sites/estuary.dev-bb4406bb-2dfd-4133-8a4c-7b737e5b0bac/consent.js"
/>,
]);
};