Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useEffect } from 'react';
- import { withRouter } from "react-router";
- import ReactGA from 'react-ga';
- const GAContext = React.createContext();
- const GA = (props) => {
- useEffect(()=>{
- ReactGA.initialize('UA-XXXXXX-1');
- },[]);
- useEffect(()=>{
- ReactGA.pageview('/' + props.location.pathname );
- },[props.location]);
- return (
- <GAContext.Provider {...props}>
- <>
- {props.children}
- </>
- </GAContext.Provider>
- )
- }
- const GAProvider = withRouter(GA);
- export default GAProvider;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement