VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse

React: Setting Up Google Analytics - Live Coding with Jesse

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Today I am going to try to get Google Analytics working. The site is using ReactJS via Next.js. Right now, I can only get analytics data on full page refresh or initial load. I need it to also log client side routing. I have also included an interview I recorded at SyntaxCon with Emily Freeman. . Live Site: https://catechetics.com Repo: https://github.com/fus-marcom/ci-react React: https://facebook.github.io/react/ Next.js: https://github.com/zeit/next.js/ Materialize: http://materializecss.com/
Date: 2022-03-14

Comments and reviews: 2


You don't have to export the constants because you use them on the same file.
Also instead of the whole logPageView function that uses a window.location.pathname, I came up with an approach that uses NextJs routes.
Import Router from 'next/router';
....
Router.onRouteChangeComplete = url => process.browser && ReactGA.pageview(url);

reply

Thanks for the helpful video. I have one question, instead of calling initialize in every page before -pageView-, can I call initialize in the route.js page and then call the pageView in the respective page, where-ever it is required?
reply
Add a review, comment






Other channel videos