React-ga: Set dimension for specific pageview?

Created on 18 Apr 2016  路  3Comments  路  Source: react-ga/react-ga

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 })
    }
  }

Most helpful comment

Yes, that would be better 馃憤

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

achhranitesh picture achhranitesh  路  3Comments

TomasVink picture TomasVink  路  3Comments

horaceleung picture horaceleung  路  6Comments

andrewmclagan picture andrewmclagan  路  3Comments

HcwXd picture HcwXd  路  4Comments