【问题标题】:Can't connect Google Analitycs with React.js无法将 Google Analytics 与 React.js 连接起来
【发布时间】:2022-01-12 16:15:29
【问题描述】:

你好吗?我严重无法将 GA 与 React 连接,我非常卡住,我看到 ID 连接器的所有视频都以 UA 开头,请帮助我

import './App.css';
// import Header from "../Header/header"
import Header2 from "../Header2/header"
import Footer from "../Footer/footer"
import Switch from "../Switch/switch"
import {BrowserRouter as Router} from "react-router-dom";
import React, {useEffect} from "react"
import ReactGa from "react-ga";

/**** Icons ****/

import { library } from '@fortawesome/fontawesome-svg-core'
import { fab, faFacebookSquare, faGoogle, faInstagramSquare, faWhatsappSquare} from '@fortawesome/free-brands-svg-icons'
import { fas, faBars, faIdCard, faGlobeAmericas, faCalendarAlt, faArrowUp} from '@fortawesome/free-solid-svg-icons'

library.add(fas, fab, faBars, faFacebookSquare, faInstagramSquare, faWhatsappSquare, faGoogle, faIdCard, faGlobeAmericas, faCalendarAlt, faArrowUp)


    function App() {
    
      useEffect(() => {
          ReactGa.initialize('G-YZ9S63BMYY')
    
          ReactGa.pageview(window.location.pathname)
      }, [])
    
      useEffect(() => {
        console.log("hola", window.location.pathname)
      })
    
      return (
          <Router>
           <Header2 />
            <React.StrictMode>
              <Switch />
            </React.StrictMode>
              <Footer />
          </Router>
      );  
    }

export default App;

从现在开始感谢大家:)

【问题讨论】:

  • 这段代码有什么问题?
  • 问题在于GA不识别连接,所以我不知道我做错了什么
  • 从 Chrome 商店获取 Google Analytics 调试器
  • 好吧,我只是尝试,也没有任何反应,我再次部署它并尝试调试器,但谷歌仍然没有向我显示任何更新,其他想法?
  • github.com/react-ga/react-ga 有一个例子,包括启用调试器,你缺少一些选项

标签: reactjs google-analytics


【解决方案1】:

GA4 必须使用 React:https://www.npmjs.com/package/react-ga4

【讨论】:

  • 这就是解决方案,非常感谢,不知道这个包更新
猜你喜欢
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
  • 2020-03-30
  • 2013-05-09
  • 1970-01-01
相关资源
最近更新 更多