简体   繁体   English

ReactJS构建和Google Analytics(分析)

[英]ReactJS build and Google Analytics

I'm using Google Analytics and other tools I have a problem regarding the build of ReactJS. 我正在使用Google Analytics(分析)和其他工具,但我在构建ReactJS时遇到问题。 I was trying to get analytics from my site using react-helmet to change the title and the HTML lang parameter depending on the route the user was in. 我试图使用react-helmet从我的网站获取分析,以根据用户所在的路线更改标题和HTML lang参数。

After the build in production, Google crawl seems to kick in before the JavaScript execute so my analytics are just working for the first language and title that was set so ( <html lang="en"> ) in my case. 构建完成后,似乎在执行JavaScript之前就开始执行Google抓取,因此我的分析仅针对我设置的第一种语言和标题( <html lang="en"> )工作。

Is there any way to get these analytics without having to generate two builds with two languages and title. 有什么方法可以获取这些分析,而不必生成具有两种语言和标题的两个版本。 Or ReactJS is just not a good solution. 还是ReactJS并不是一个好的解决方案。

https://codesandbox.io/s/okei4 https://codesandbox.io/s/okei4

Check out how react-ga could be used in a ReactJS project. 了解如何在ReactJS项目中使用react-ga。 This code is fully working so in Google Analytics I can see every page was visited. 该代码可以正常运行,因此在Google Analytics(分析)中,我可以看到访问的每个页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM