How to set up Google Analytics for React-Router?

后端 未结 15 656
名媛妹妹
名媛妹妹 2020-12-12 12:25

I\'m trying set up Google Analytics on my react site, and have come across a few packages, but none of which has the kind of set up that I have in terms of examples. Was ho

15条回答
  •  爱一瞬间的悲伤
    2020-12-12 13:15

    basic react-ga implementation with your index.js

    var ReactGA = require('react-ga'); // require the react-ga module
    ReactGA.initialize('Your-UA-ID-HERE'); // add your UA code 
    
    function logPageView() { // add this function to your component
      ReactGA.set({ page: window.location.pathname + window.location.search });
      ReactGA.pageview(window.location.pathname + window.location.search);
    }
    
    React.render((
     // insert onUpdate props here
        
            
            
            
            
                
            
            
            
        
        
    ), document.getElementById('root'));
    

提交回复
热议问题