feat(analytics): add google analytics with anonymized ip (#150)

This commit is contained in:
Rui Saraiva 2020-06-27 22:10:42 +01:00 committed by GitHub
parent 90bd7436e8
commit 27cabcf6e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,29 @@
import React from 'react'
import Document, { Html, Head, Main, NextScript } from 'next/document'
const isProd = process.env.NODE_ENV === 'production'
class MyDocument extends Document {
render() {
return (
<Html lang="en">
<Head />
<Head>
{isProd && <script async src="https://www.googletagmanager.com/gtag/js?id=UA-171039315-1" />}
{isProd && (
<script
dangerouslySetInnerHTML={{
__html: `
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-171039315-1', { 'anonymize_ip': true });
</script>
`,
}}
/>
)}
</Head>
<body className="preload">
<script src="/js/noflash.js" />
<Main />