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
There is no need for any special library and some answers here look uncomplete. Just add the script to and noscript to in _document.js
import Head from 'next/document' `, }} />