import ensure from '@redux-beacon/ensure'
const pageview = (action, prevState) => ({
route: action.payload.location.pathname,
referrer: prevState.currentRoute,
// Returns true if the event matches the schema
const isValidPageView = event =>
!joi.validate(event, joi.object().keys({
hitType: joi.string().only('pageview').required(),
page: joi.string().disallow('/404'),
LOCATION_CHANGE: ensure(isValidPageView, pageview)