私は次のjsアプリケーションにgoogle analyticsを挿入するためにreact-ga npmモジュールを使用していました。そしてそれは単に、このようなものだった:Googleタグマネージャを使用してNext-J用にGoogle Analyticsを設定するにはどうすればよいですか?
import ReactGA from 'react-ga'
export const initGA =() => {
ReactGA.initialize('UA-*******-*', {
titleCase: false
})
}
export const logPageView =() => {
if (window.location.href.split('?')[1]) {
ReactGA.set({page: window.location.pathname + '?' + window.location.href.split('?')[1]})
ReactGA.pageview(window.location.pathname + '?' + window.location.href.split('?')[1])
} else {
ReactGA.set({page: window.location.pathname})
ReactGA.pageview(window.location.pathname)
}
}
し、私はこのように(それは私のアプリのすべてのページに挿入された)私のヘッダー内のlogPageView関数を呼び出していました。今、私が使用したい
componentDidMount() {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
}
componentWillReceiveProps() {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
}
アナリティクスのページビューを処理するGoogleタグマネージャどうすればこのことができますか?