Adds entry and exit pages to Top Pages module (#712)
* Initial Pass * Adds support for page visits counting by referrer * Includes goal selection in entry and exit computation * Adds goal-based entry and exit page stats, formatting, code cleanup * Changelog * Format * Exit rate, visit duration, updated tests * I keep forgetting to format :/ * Tests, last time * Fixes double counting, exit rate >100%, relevant tests * Fixes exit pages on filter and goal states * Adds entry and exit filters, fixes various bugs * Fixes discussed issues * Format * Fixes impossible case in tests Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date. * Format * Removes boolean function parameter in favor of separate function * Adds support for queries that use `page` filter as `entry-page` * Format * Makes loader/title interaction in sources report consistentpull/762/head
parent
98afadcb6d
commit
ff32218bd0
@ -0,0 +1,116 @@
|
||||
import React from "react";
|
||||
import { Link } from 'react-router-dom'
|
||||
import { withRouter } from 'react-router-dom'
|
||||
|
||||
import Modal from './modal'
|
||||
import * as api from '../../api'
|
||||
import numberFormatter, { durationFormatter } from '../../number-formatter'
|
||||
import {parseQuery} from '../../query'
|
||||
|
||||
class EntryPagesModal extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
loading: true,
|
||||
query: parseQuery(props.location.search, props.site),
|
||||
pages: [],
|
||||
page: 1,
|
||||
moreResultsAvailable: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadPages();
|
||||
}
|
||||
|
||||
loadPages() {
|
||||
const {query, page, pages} = this.state;
|
||||
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, query, {limit: 100, page})
|
||||
.then((res) => this.setState((state) => ({loading: false, pages: state.pages.concat(res), moreResultsAvailable: res.length === 100})))
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
this.setState({loading: true, page: this.state.page + 1}, this.loadPages.bind(this))
|
||||
}
|
||||
|
||||
showVisitDuration() {
|
||||
return this.state.query.period !== 'realtime'
|
||||
}
|
||||
|
||||
formatBounceRate(page) {
|
||||
if (typeof(page.bounce_rate) === 'number') {
|
||||
return page.bounce_rate + '%'
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
renderPage(page) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
query.set('entry_page', page.name)
|
||||
|
||||
return (
|
||||
<tr className="text-sm dark:text-gray-200" key={page.name}>
|
||||
<td className="p-2">
|
||||
<Link to={{pathname: `/${encodeURIComponent(this.props.site.domain)}`, search: query.toString()}} className="hover:underline">{page.name}</Link>
|
||||
</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(page.count)}</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(page.entries)}</td>
|
||||
{this.showVisitDuration() && <td className="p-2 w-32 font-medium" align="right">{durationFormatter(page.visit_duration)}</td>}
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
renderLoading() {
|
||||
if (this.state.loading) {
|
||||
return <div className="loading my-16 mx-auto"><div></div></div>
|
||||
} else if (this.state.moreResultsAvailable) {
|
||||
return (
|
||||
<div className="w-full text-center my-4">
|
||||
<button onClick={this.loadMore.bind(this)} type="button" className="button">
|
||||
Load more
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
renderBody() {
|
||||
if (this.state.pages) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<h1 className="text-xl font-bold dark:text-gray-100">Entry Pages</h1>
|
||||
|
||||
<div className="my-4 border-b border-gray-300"></div>
|
||||
<main className="modal__content">
|
||||
<table className="w-full table-striped table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="left">Page url</th>
|
||||
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Unique Entrances</th>
|
||||
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Total Entrances</th>
|
||||
{<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Visit Duration</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{ this.state.pages.map(this.renderPage.bind(this)) }
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal site={this.props.site}>
|
||||
{ this.renderBody() }
|
||||
{ this.renderLoading() }
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(EntryPagesModal)
|
||||
@ -0,0 +1,112 @@
|
||||
import React from "react";
|
||||
import { Link } from 'react-router-dom'
|
||||
import { withRouter } from 'react-router-dom'
|
||||
|
||||
import Modal from './modal'
|
||||
import * as api from '../../api'
|
||||
import numberFormatter from '../../number-formatter'
|
||||
import {parseQuery} from '../../query'
|
||||
|
||||
class ExitPagesModal extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
loading: true,
|
||||
query: parseQuery(props.location.search, props.site),
|
||||
pages: [],
|
||||
page: 1,
|
||||
moreResultsAvailable: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadPages();
|
||||
}
|
||||
|
||||
loadPages() {
|
||||
const {query, page, pages} = this.state;
|
||||
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/exit-pages`, query, {limit: 100, page})
|
||||
.then((res) => this.setState((state) => ({loading: false, pages: state.pages.concat(res), moreResultsAvailable: res.length === 100})))
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
this.setState({loading: true, page: this.state.page + 1}, this.loadPages.bind(this))
|
||||
}
|
||||
|
||||
formatPercentage(number) {
|
||||
if (typeof(number) === 'number') {
|
||||
return number + '%'
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
renderPage(page) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
query.set('exit_page', page.name)
|
||||
|
||||
return (
|
||||
<tr className="text-sm dark:text-gray-200" key={page.name}>
|
||||
<td className="p-2">
|
||||
<Link to={{pathname: `/${encodeURIComponent(this.props.site.domain)}`, search: query.toString()}} className="hover:underline">{page.name}</Link>
|
||||
</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(page.count)}</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(page.exits)}</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{this.formatPercentage(page.exit_rate)}</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
renderLoading() {
|
||||
if (this.state.loading) {
|
||||
return <div className="loading my-16 mx-auto"><div></div></div>
|
||||
} else if (this.state.moreResultsAvailable) {
|
||||
return (
|
||||
<div className="w-full text-center my-4">
|
||||
<button onClick={this.loadMore.bind(this)} type="button" className="button">
|
||||
Load more
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
renderBody() {
|
||||
if (this.state.pages) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<h1 className="text-xl font-bold dark:text-gray-100">Exit Pages</h1>
|
||||
|
||||
<div className="my-4 border-b border-gray-300"></div>
|
||||
<main className="modal__content">
|
||||
<table className="w-full table-striped table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="left">Page url</th>
|
||||
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Unique Exits</th>
|
||||
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Total Exits</th>
|
||||
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Exit Rate</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{ this.state.pages.map(this.renderPage.bind(this)) }
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal site={this.props.site}>
|
||||
{ this.renderBody() }
|
||||
{ this.renderLoading() }
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(ExitPagesModal)
|
||||
@ -0,0 +1,86 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom'
|
||||
import FlipMove from 'react-flip-move';
|
||||
|
||||
import FadeIn from '../../fade-in'
|
||||
import Bar from '../bar'
|
||||
import MoreLink from '../more-link'
|
||||
import numberFormatter from '../../number-formatter'
|
||||
import { eventName } from '../../query'
|
||||
import * as api from '../../api'
|
||||
|
||||
export default class EntryPages extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {loading: true}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchPages()
|
||||
if (this.props.timer) this.props.timer.onTick(this.fetchPages.bind(this))
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.query !== prevProps.query) {
|
||||
this.setState({loading: true, pages: null})
|
||||
this.fetchPages()
|
||||
}
|
||||
}
|
||||
|
||||
fetchPages() {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, this.props.query)
|
||||
.then((res) => this.setState({loading: false, pages: res}))
|
||||
}
|
||||
|
||||
renderPage(page) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
query.set('entry_page', page.name)
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between my-1 text-sm" key={page.name}>
|
||||
<div className="w-full h-8 truncate" style={{maxWidth: 'calc(100% - 4rem)'}}>
|
||||
<Bar count={page.count} all={this.state.pages} bg="bg-orange-50 dark:bg-gray-500 dark:bg-opacity-15" />
|
||||
<span className="flex px-2 group dark:text-gray-300" style={{marginTop: '-26px'}} >
|
||||
<Link to={{pathname: window.location.pathname, search: query.toString()}} className="block hover:underline">{page.name}</Link>
|
||||
<a target="_blank" href={'http://' + this.props.site.domain + page.name} className="hidden group-hover:block">
|
||||
<svg className="inline h-4 w-4 ml-1 -mt-1 text-gray-600 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20"><path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path><path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"></path></svg>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<span className="font-medium dark:text-gray-200">{numberFormatter(page.count)}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
renderList() {
|
||||
if (this.state.pages && this.state.pages.length > 0) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div className="flex items-center mt-3 mb-2 justify-between text-gray-500 dark:text-gray-400 text-xs font-bold tracking-wide">
|
||||
<span>Page url</span>
|
||||
<span>Unique Entrances</span>
|
||||
</div>
|
||||
|
||||
<FlipMove>
|
||||
{ this.state.pages.map(this.renderPage.bind(this)) }
|
||||
</FlipMove>
|
||||
</React.Fragment>
|
||||
)
|
||||
} else {
|
||||
return <div className="text-center mt-44 font-medium text-gray-500 dark:text-gray-400">No data yet</div>
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { loading } = this.state;
|
||||
return (
|
||||
<React.Fragment>
|
||||
{ loading && <div className="loading mt-44 mx-auto"><div></div></div> }
|
||||
<FadeIn show={!loading}>
|
||||
{ this.renderList() }
|
||||
</FadeIn>
|
||||
{!loading && <MoreLink site={this.props.site} list={this.state.pages} endpoint="entry-pages" />}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom'
|
||||
import FlipMove from 'react-flip-move';
|
||||
|
||||
import FadeIn from '../../fade-in'
|
||||
import Bar from '../bar'
|
||||
import MoreLink from '../more-link'
|
||||
import numberFormatter from '../../number-formatter'
|
||||
import { eventName } from '../../query'
|
||||
import * as api from '../../api'
|
||||
|
||||
export default class ExitPages extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {loading: true}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchPages()
|
||||
if (this.props.timer) this.props.timer.onTick(this.fetchPages.bind(this))
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.query !== prevProps.query) {
|
||||
this.setState({loading: true, pages: null})
|
||||
this.fetchPages()
|
||||
}
|
||||
}
|
||||
|
||||
fetchPages() {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/exit-pages`, this.props.query)
|
||||
.then((res) => this.setState({loading: false, pages: res}))
|
||||
}
|
||||
|
||||
renderPage(page) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
query.set('exit_page', page.name)
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between my-1 text-sm" key={page.name}>
|
||||
<div className="w-full h-8 truncate" style={{maxWidth: 'calc(100% - 4rem)'}}>
|
||||
<Bar count={page.count} all={this.state.pages} bg="bg-orange-50 dark:bg-gray-500 dark:bg-opacity-15" />
|
||||
<span className="flex px-2 group dark:text-gray-300" style={{marginTop: '-26px'}} >
|
||||
<Link to={{pathname: window.location.pathname, search: query.toString()}} className="block hover:underline">{page.name}</Link>
|
||||
<a target="_blank" href={'http://' + this.props.site.domain + page.name} className="hidden group-hover:block">
|
||||
<svg className="inline h-4 w-4 ml-1 -mt-1 text-gray-600 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20"><path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path><path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"></path></svg>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<span className="font-medium dark:text-gray-200">{numberFormatter(page.count)}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
renderList() {
|
||||
if (this.state.pages && this.state.pages.length > 0) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div className="flex items-center mt-3 mb-2 justify-between text-gray-500 dark:text-gray-400 text-xs font-bold tracking-wide">
|
||||
<span>Page url</span>
|
||||
<span>Unique Exits</span>
|
||||
</div>
|
||||
|
||||
<FlipMove>
|
||||
{ this.state.pages.map(this.renderPage.bind(this)) }
|
||||
</FlipMove>
|
||||
</React.Fragment>
|
||||
)
|
||||
} else {
|
||||
return <div className="text-center mt-44 font-medium text-gray-500 dark:text-gray-400">No data yet</div>
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { loading } = this.state;
|
||||
return (
|
||||
<React.Fragment>
|
||||
{ loading && <div className="loading mt-44 mx-auto"><div></div></div> }
|
||||
<FadeIn show={!loading}>
|
||||
{ this.renderList() }
|
||||
</FadeIn>
|
||||
{!loading && <MoreLink site={this.props.site} list={this.state.pages} endpoint="exit-pages" />}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import Visits from './pages'
|
||||
import EntryPages from './entry-pages'
|
||||
import ExitPages from './exit-pages'
|
||||
import FadeIn from '../../fade-in'
|
||||
|
||||
const labelFor = {
|
||||
'pages': 'Top Pages',
|
||||
'entry-pages': 'Entry Pages',
|
||||
'exit-pages': 'Exit Pages',
|
||||
}
|
||||
|
||||
export default class Pages extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.tabKey = 'pageTab__' + props.site.domain
|
||||
const storedTab = window.localStorage[this.tabKey]
|
||||
this.state = {
|
||||
mode: storedTab || 'pages'
|
||||
}
|
||||
}
|
||||
|
||||
renderContent() {
|
||||
if (this.state.mode === 'pages') {
|
||||
return <Visits site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
||||
} else if (this.state.mode === 'entry-pages') {
|
||||
return <EntryPages site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
||||
} else if (this.state.mode === 'exit-pages') {
|
||||
return <ExitPages site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
||||
}
|
||||
}
|
||||
|
||||
setMode(mode) {
|
||||
return () => {
|
||||
window.localStorage[this.tabKey] = mode
|
||||
this.setState({mode})
|
||||
}
|
||||
}
|
||||
|
||||
renderPill(name, mode) {
|
||||
const isActive = this.state.mode === mode
|
||||
|
||||
if (isActive) {
|
||||
return <li className="inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold border-b-2 border-indigo-700 dark:border-indigo-500">{name}</li>
|
||||
} else {
|
||||
return <li className="hover:text-indigo-600 cursor-pointer" onClick={this.setMode(mode)}>{name}</li>
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const filters = this.props.query.filters
|
||||
return (
|
||||
<div className="stats-item">
|
||||
<div className="bg-white dark:bg-gray-825 shadow-xl rounded p-4 relative" style={{height: '436px'}}>
|
||||
|
||||
<div className="w-full flex justify-between">
|
||||
<h3 className="font-bold dark:text-gray-100">{labelFor[this.state.mode] || 'Page Visits'}</h3>
|
||||
|
||||
<ul className="flex font-medium text-xs text-gray-500 dark:text-gray-400 space-x-2">
|
||||
{ this.renderPill('Top Pages', 'pages') }
|
||||
{ this.renderPill('Entry Pages', 'entry-pages') }
|
||||
{ this.renderPill('Exit Pages', 'exit-pages') }
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{ this.renderContent() }
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue