之前我在我的next js应用中使用react-ga npm模块来插入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函数,代码如下:
```javascript logPageView(); ``` componentDidMount () {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
}
componentWillReceiveProps () {
if (!window.GA_INITIALIZED) {
initGA()
window.GA_INITIALIZED = true
}
logPageView()
}
现在我想使用Google Tag Manager来处理分析页面查看。我该怎么做?
.replace(/\n\s*/g, "")
来删除换行符。 - Lucas Vazquez