React-starter-kit: How to make GA(Google analytics) detect changed router when using Link component

Created on 31 Aug 2016  路  6Comments  路  Source: kriasoft/react-starter-kit

Hi all,
I monitors GA module "Top active pages", when direct to new router using Link component, GA is not recognize url changed.
Thanks

question

All 6 comments

Hook it on history or hook it on router

It should, did you see this code?
Or maybe you forgot to set GOOGLE_TRACKING_ID environment variable?

Ahh, i was inserted <script src="/google-analytics.js"></script> to enable content security policy in helmet like below:

scriptSrc: ["'self'", 'www.google-analytics.com', 'ajax.googleapis.com'],

I'm current using:

if (window.ga) {
      window.ga('send', 'pageview');
}
<script src="/google-analytics.js">

Hi @langpavel and @frenzzy,
I tried with origin code from react-startkit redux branch.
I added GA code to config file like below:

export const analytics = {
  // https://analytics.google.com/
  google: {
    trackingId: 'UA-81634517-1', // UA-XXXXX-X
  },
};

--> still now work :(

and I tried something else:

export function navigate(descriptor) {
  if (window.ga) {
    window.ga('send', 'pageview');
  }
  return (dispatch, _, { history }) => history.push(descriptor);
}
export default {
  path: '/login',
  action() {
    if (window.ga) {
      window.ga('send', 'pageview');
    }
    return <Login />;
  },
};

but isn't work when monitor on GA. please take a look.
Thanks

@langpavel , @frenzzy could you help me please !
I have no solution for this :(

Hi all,
I had resolved this issues by add more param like below to client.js:

ga('send', 'pageview', window.location.pathname + window.location.search);

Thanks :)

Was this page helpful?
0 / 5 - 0 ratings