analytics/assets/js/dashboard/stats/pages/entry-pages.js
Vignesh Joglekar ff32218bd0
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 consistent
2021-02-26 11:02:37 +02:00

87 lines
3.2 KiB
JavaScript

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>
)
}
}