formerly I was using react-ga npm module to insert google analytics in my next js app. and It was simply like this:
import ReactGA from \'react-ga\'
export cons
In order to use Google Tag Manager you should inject your tag manager script on every page. since _document.js
is the wrapper for every page, you should add the GTM script to _document.js
in the head section like this:
...
Now you are all set to use Google Tag Manager in your next-js app. You should only proceed to handle pageview and other analytics related stuff from your GTM dashboard.
To set up google analytics pageview for single page applications(like nextjs) you can follow these steps.