I have added the JavaScript that I need to the bottom of my pages so that I can make use of Google Analytics. Only problem is that I am sure that it is counting all my devel
Unfortunatelly, it doesn't seem to be possible to exclude localhost
from the reporting when using App + Web Properties type of setup:
Displaying Filters for web-only Properties only. Filters can't be applied to App + Web Properties.
For the nextjs web application, especially ones which are using static generation
or SSR
this would work:
In your document.tsx
export default class MyDocument extends Document {
render() {
return (
. . . . .
{process.env.NODE_ENV === 'production' ? injectAnalytics() : ''}
);
}
}
where injectAnalytics
is a function which returns your GA code, for instance:
function injectAnalytics(): React.ReactFragment {
return <>
{/* Global Site Tag (gtag.js) - Google Analytics */}
>
}