|
|
import page, { type Callback } from '@automattic/calypso-router'; |
|
|
import { |
|
|
follows, |
|
|
insights, |
|
|
post, |
|
|
site, |
|
|
summary, |
|
|
wordAds, |
|
|
subscribers, |
|
|
redirectToActivity, |
|
|
redirectToDefaultModulePage, |
|
|
redirectToDefaultWordAdsPeriod, |
|
|
purchase, |
|
|
emailStats, |
|
|
emailSummary, |
|
|
redirectToDaySummary, |
|
|
} from 'calypso/my-sites/stats/controller'; |
|
|
import config from './lib/config-api'; |
|
|
import { makeLayout, render as clientRender } from './page-middleware/layout'; |
|
|
import 'calypso/my-sites/stats/style.scss'; |
|
|
|
|
|
const statsPage = ( url: string, controller: Callback ) => { |
|
|
page( url, controller, makeLayout, clientRender ); |
|
|
}; |
|
|
|
|
|
const redirectToSiteTrafficPage = () => { |
|
|
page.redirect( `/stats/day/${ config( 'blog_id' ) }` ); |
|
|
}; |
|
|
|
|
|
export default function ( pageBase = '/' ) { |
|
|
const validPeriods = [ 'day', 'week', 'month', 'year' ].join( '|' ); |
|
|
const validTrafficPagePeriods = [ 'hour', 'day', 'week', 'month', 'year' ].join( '|' ); |
|
|
const validEmailPeriods = [ 'hour', 'day' ].join( '|' ); |
|
|
|
|
|
const validModules = [ |
|
|
'posts', |
|
|
'referrers', |
|
|
'clicks', |
|
|
'countryviews', |
|
|
'locations', |
|
|
'authors', |
|
|
'videoplays', |
|
|
'videodetails', |
|
|
'filedownloads', |
|
|
'searchterms', |
|
|
'annualstats', |
|
|
'utm', |
|
|
'devices', |
|
|
].join( '|' ); |
|
|
|
|
|
page.base( pageBase ); |
|
|
|
|
|
|
|
|
|
|
|
page( '/', '/stats/day/:site' ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/insights/:site', insights ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/subscribers/:site', subscribers ); |
|
|
statsPage( `/stats/subscribers/:period(${ validPeriods })/:site`, subscribers ); |
|
|
|
|
|
|
|
|
statsPage( `/stats/:period(${ validTrafficPagePeriods })/:site`, site ); |
|
|
|
|
|
|
|
|
|
|
|
statsPage( `/stats/:module(${ validModules })/:site`, redirectToDefaultModulePage ); |
|
|
|
|
|
|
|
|
statsPage( `/stats/:period(${ validPeriods })/:module(${ validModules })/:site`, summary ); |
|
|
|
|
|
statsPage( `/stats/hour/:module(${ validModules })/:site`, redirectToDaySummary ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/post/:post_id/:site', post ); |
|
|
statsPage( '/stats/page/:post_id/:site', post ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/follows/comment/:site', follows ); |
|
|
statsPage( '/stats/follows/comment/:page_num/:site', follows ); |
|
|
|
|
|
statsPage( '/stats/activity/:site?', redirectToActivity ); |
|
|
|
|
|
statsPage( `/stats/ads/:period(${ validPeriods })/:site`, wordAds ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/wordads/(.*)', redirectToDefaultWordAdsPeriod ); |
|
|
statsPage( '/stats/ads/(.*)', redirectToDefaultWordAdsPeriod ); |
|
|
|
|
|
|
|
|
statsPage( '/stats/purchase/:site', purchase ); |
|
|
|
|
|
|
|
|
statsPage( `/stats/email/:statType/:period(${ validEmailPeriods })/:email_id/:site`, emailStats ); |
|
|
statsPage( '/stats/day/emails/:site', emailSummary ); |
|
|
|
|
|
|
|
|
statsPage( '*', redirectToSiteTrafficPage ); |
|
|
|
|
|
|
|
|
page( { hashbang: true } ); |
|
|
} |
|
|
|