-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google analytics #64
Comments
Not documented yet but there's a |
How do you get that |
@SachaG you need to export a function from gatsby-browser.js called |
Thanks, here's what I ended up with in my import ReactGA from 'react-ga';
ReactGA.initialize('UA-xxxxxx-x');
exports.onRouteUpdate = (state, page, pages) => {
ReactGA.pageview(state.pathname);
}; I'm not sure if that's the best way to do it though. I'm using React-GA btw. |
Seems reasonable!
|
Hi ! The |
@GuillaumeHaben can you post the code you're using? |
@KyleAMathews I'm using the same code as Sasha (except with my GA id instead of xxxxx). I've also installed react-ga. |
We'd need more info to help. It sounds like it should work. Is there errors
|
You can check my repo here. I tried the html.js and the Edit : I finally managed to get it work by following this issue. My script had to be surrounded by ` as you can see here |
Glad you got it working! And I should finish converting my blog out of Coffeescript — that it's mixed JS/CS right now is confusing. |
Is the setup described here #64 (comment) the "correct way" to setup analytics? Add a file called gatsby-browser.js with and add the following code? import ReactGA from 'react-ga';
ReactGA.initialize('UA-xxxxxx-x');
exports.onRouteUpdate = (state, page, pages) => {
ReactGA.pageview(state.pathname);
}; UPDATE: Confirmed this worked |
I did what @timarney did, but I got |
I got it working using: import ReactGA from "react-ga";
ReactGA.initialize("UA-XXXX");
exports.onClientEntry = () => {
ReactGA.set({ page: window.location.pathname });
ReactGA.pageview(window.location.pathname);
}; |
@franzejr I find that the
|
Having the error below with element type. Failed prop type: Invalid prop `children` of type `array` supplied to `Layout`, expected a single ReactElement.
Need to be able to fire off page views to google analytics.
The text was updated successfully, but these errors were encountered: