import { Fragment } from 'react' ; import { withRouter } from 'react-router-dom' ; import { getRouteConfigByPath } from '@config' ; import { useAnalytics } from '@services/Analytics' ; import { useEffectOnce } from '@vendor' ; const stripRouteParam = ( path ) => path . split ( '/:' ) [ 0 ] ; export const PageVisitsAnalytics = withRouter ( ( { history , location } ) => { const { trackPage } = useAnalytics ( ) ; useEffectOnce ( ( ) => { history . listen ( ( to ) => { if ( to . pathname === location . pathname ) return ; const { name , title } = getRouteConfigByPath ( stripRouteParam ( to . pathname ) ) || { } ; trackPage ( { name , title } ) ; } ) ; } ) ; return < Fragment />; } ) ;