security-checklist/pages/_document.js
2019-01-12 17:52:43 -08:00

71 lines
1.9 KiB
JavaScript

// @flow
import * as React from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
import { GA_TRACKING_ID } from '../lib/gtag';
export default class MyDocument extends Document {
// $FlowFixMe
static getInitialProps({ renderPage }) {
const sheet = new ServerStyleSheet();
const page = renderPage(App => props =>
sheet.collectStyles(<App {...props} />)
);
const styleTags = sheet.getStyleElement();
return { ...page, styleTags };
}
render() {
return (
<html lang="en">
<Head>
<meta
name="viewport"
content="width=device-width, initial-scale=1"
key="viewport"
/>
<meta charSet="utf-8" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/static/meta/favicon-96x96.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/static/meta/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/static/meta/favicon-16x16.png"
/>
{this.props.styleTags}
</Head>
<body>
<Main />
<NextScript />
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
/>
<script
// eslint-disable-next-line
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}');
`,
}}
/>
</body>
</html>
);
}
}