I'm trying to set an author dimension for some page views and do that by calling ga.set({ dimension1: 'author-of-that-page' }) when a certain component is mounted. However, I noticed that Google Analytics keeps sending that dimension for all subsequent page views. Is there a way to tie a dimension for just a specific pageview? Or should I "unset" the dimension when the component unmounts? e.g:
componentWillMount() {
if (__CLIENT__) {
console.log('pageview in componentWillMount!')
ga.set({ 'dimension1': 'test' })
ga.pageview(window.location.pathname)
}
}
componentWillUnmount() {
if (__CLIENT__) {
ga.set({ 'dimension1': null })
}
}
edit: above code can be simplified with just:
componentWillMount() {
if (__CLIENT__) {
console.log('pageview in componentWillMount!')
ga.set({ dimension1: 'test' })
ga.pageview(window.location.pathname)
ga.set({ dimension1: null })
}
}
The current react-ga is not capable of that functionality. What do you say we add a ga.send() function that you can call like this?
ga.send('pageview', page, {
dimension1: 'test'
});
That way, the dimension will only be set for that page view.
Yes, that would be better 馃憤
Fixed in #73 which implements ga.send(). It is available in 1.5.0.
Most helpful comment
Yes, that would be better 馃憤