This marketing blurb of this startup + MIT is super super super cool! But then after that….my immediate question: What’s the downside? There’s always cause/effect. action / reaction. Punch a hole in the universe? Demagnetize the poles? Do all birds migrate to fusion power plants instead of where they’re supposed to go? 😆
Because of the mix of static / server side / dynamic page options in a NextJS app, you have to handle Google Analytics in a specific way. It’s simple though: Create a _document.ts
file in /pages/ like so:
import Document, { Html, Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
render() {
return (
<Html>
<Head>
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=UA-YOUR_TAG_HERE-1`}
/>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-YOUR_TAG_HERE-1', {
page_path: window.location.pathname,
});
gtag('config', 'G-YOUR_TAG_HERE');
`,
}}
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
This is an archived post, some things might not display right.
Copyright © Rick BlalockView Archive