Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import React, { useEffect } from 'react';
  2. import { withRouter } from "react-router";
  3. import ReactGA from 'react-ga';
  4.  
  5. const GAContext = React.createContext();
  6. const GA = (props) => {
  7.  
  8. useEffect(()=>{
  9. ReactGA.initialize('UA-XXXXXX-1');
  10. },[]);
  11.  
  12. useEffect(()=>{
  13.  
  14. ReactGA.pageview('/' + props.location.pathname );
  15.  
  16. },[props.location]);
  17.  
  18.  
  19. return (
  20. <GAContext.Provider {...props}>
  21. <>
  22. {props.children}
  23. </>
  24. </GAContext.Provider>
  25. )
  26. }
  27. const GAProvider = withRouter(GA);
  28. export default GAProvider;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement