import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import ReactGA from 'react-ga';

const useAnalytics = pageTitle => {
  const location = useLocation();

  useEffect(() => {
    ReactGA.pageview(location.pathname, null, pageTitle);
    console.log(`Google Analytics running for ${pageTitle}`);
  }, []);
};

export default useAnalytics;
