Nullstack wrapper for Google Analytics
npm install --save nullstack-google-analytics
All you have to do is import and render the Google Analytics tag with your project ID as an attribute
This component will listen for Nullstack route changes and track a PageView
import Nullstack from 'nullstack';
import GoogleAnalytics from 'nullstack-google-analytics';
class Application extends Nullstack {
render() {
return (
<main>
{/* your routes go here */}
<GoogleAnalytics id="REPLACE_WITH_YOUR_GOOGLE_ANALYTICS_ID" />
</main>
)
}
}
export default Application;
This component preconnects to https://www.googletagmanager.com and only adds the script tag once the application is hydrated to avoid blocking the first paint.
Nullstack Google Analytics is released under the MIT License.