diff --git a/assets/js/dashboard/stats/modals/referrer-drilldown.js b/assets/js/dashboard/stats/modals/referrer-drilldown.js
index 8a8723bff..c62c27671 100644
--- a/assets/js/dashboard/stats/modals/referrer-drilldown.js
+++ b/assets/js/dashboard/stats/modals/referrer-drilldown.js
@@ -19,7 +19,7 @@ class ReferrerDrilldownModal extends React.Component {
const detailed = this.showExtra()
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100, detailed})
- .then((res) => this.setState({loading: false, referrers: res.referrers, totalVisitors: res.total_visitors}))
+ .then((referrers) => this.setState({loading: false, referrers: referrers}))
}
showExtra() {
diff --git a/assets/js/dashboard/stats/reports/list.js b/assets/js/dashboard/stats/reports/list.js
index bd78eb004..94e4b3050 100644
--- a/assets/js/dashboard/stats/reports/list.js
+++ b/assets/js/dashboard/stats/reports/list.js
@@ -7,6 +7,7 @@ import FadeIn from '../../fade-in'
import MoreLink from '../more-link'
import Bar from '../bar'
import LazyLoader from '../../components/lazy-loader'
+import classNames from 'classnames'
const MAX_ITEMS = 9
const MIN_HEIGHT = 380
@@ -15,10 +16,29 @@ const ROW_GAP_HEIGHT = 4
const DATA_CONTAINER_HEIGHT = (ROW_HEIGHT + ROW_GAP_HEIGHT) * (MAX_ITEMS - 1) + ROW_HEIGHT
const COL_MIN_WIDTH = 70
-function ExternalLink({item, externalLinkDest}) {
- if (externalLinkDest) {
- const dest = externalLinkDest(item)
+function FilterLink({filterQuery, onClick, children}) {
+ const className = classNames('max-w-max w-full flex md:overflow-hidden', {
+ 'hover:underline': !!filterQuery
+ })
+
+ if (filterQuery) {
+ return (
+
+ { children }
+
+ )
+ } else {
+ return { children }
+ }
+}
+function ExternalLink({item, externalLinkDest}) {
+ const dest = externalLinkDest && externalLinkDest(item)
+ if (dest) {
return (
{
query.set(key, value)
}))
+ return query
+ }
+
+ function renderBarFor(listItem) {
const lightBackground = props.color || 'bg-green-50'
const noop = () => {}
const metricToPlot = metrics[0].name
@@ -189,14 +215,14 @@ export default function ListReport(props) {
plot={metricToPlot}
>
-
+
{maybeRenderIconFor(listItem)}
{listItem.name}
-
-
+
+
diff --git a/assets/js/dashboard/stats/sources/referrer-list.js b/assets/js/dashboard/stats/sources/referrer-list.js
index 21a9a5083..75d1c2ca0 100644
--- a/assets/js/dashboard/stats/sources/referrer-list.js
+++ b/assets/js/dashboard/stats/sources/referrer-list.js
@@ -1,177 +1,48 @@
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 '../../util/number-formatter'
import * as api from '../../api'
-import LazyLoader from '../../components/lazy-loader'
-
-function LinkOption(props) {
- if (props.disabled) {
- return {props.children}
- } else {
- props = Object.assign({}, props, { className: props.className + ' hover:underline' })
- return {props.children}
- }
-}
-
-export default class Referrers extends React.Component {
- constructor(props) {
- super(props)
- this.state = { loading: true }
- this.onVisible = this.onVisible.bind(this)
- this.fetchReferrers = this.fetchReferrers.bind(this)
- }
-
- onVisible() {
- this.fetchReferrers()
- if (this.props.query.period === 'realtime') {
- document.addEventListener('tick', this.fetchReferrers)
- }
- }
-
- componentDidUpdate(prevProps) {
- if (this.props.query !== prevProps.query) {
- this.setState({ loading: true, referrers: null })
- this.fetchReferrers()
- }
- }
-
- componentWillUnmount() {
- document.removeEventListener('tick', this.fetchReferrers)
- }
-
- showConversionRate() {
- return !!this.props.query.filters.goal
- }
+import * as url from '../../util/url'
+import { VISITORS_METRIC, maybeWithCR } from '../reports/metrics'
+import ListReport from '../reports/list'
- fetchReferrers() {
- if (this.props.query.filters.source) {
- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/${encodeURIComponent(this.props.query.filters.source)}`, this.props.query)
- .then((res) => res.search_terms || res.referrers)
- .then((referrers) => this.setState({ loading: false, referrers: referrers }))
- } else if (this.props.query.filters.goal) {
- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers`, this.props.query)
- .then((res) => this.setState({ loading: false, referrers: res }))
- } else {
- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.props.query)
- .then((res) => this.setState({ loading: false, referrers: res }))
- }
+export default function Referrers({site, query}) {
+ function fetchReferrers() {
+ return api.get(url.apiPath(site, `/referrers/${encodeURIComponent(query.filters.source)}`), query, {limit: 9})
}
- renderExternalLink(referrer) {
- if (this.props.query.filters.source && this.props.query.filters.source !== 'Google' && referrer.name !== 'Direct / None') {
- return (
-
-
-
- )
- }
- return null
+ function externalLinkDest(referrer) {
+ if (referrer.name === 'Direct / None') { return null }
+ return `https://${referrer.name}`
}
- renderReferrer(referrer) {
- const maxWidthDeduction = this.showConversionRate() ? "10rem" : "5rem"
- const query = new URLSearchParams(window.location.search)
- query.set('referrer', referrer.name)
-
- return (
-
-
-
-
-
- {referrer.name}
-
- {this.renderExternalLink(referrer)}
-
-
-
{numberFormatter(referrer.visitors)}
- {this.showConversionRate() &&
{referrer.conversion_rate}%}
-
- )
- }
-
- label() {
- if (this.props.query.period === 'realtime') {
- return 'Current visitors'
- }
-
- if (this.showConversionRate()) {
- return 'Conversions'
- }
-
- return 'Visitors'
+ function getFilterFor(referrer) {
+ if (referrer.name === 'Direct / None') { return null }
+ return { referrer: referrer.name }
}
- renderList() {
- if (this.state.referrers.length > 0) {
- return (
-
-
-
Referrer
-
-
- {this.label()}
- {this.showConversionRate() && CR}
-
-
-
-
- {this.state.referrers.map(this.renderReferrer.bind(this))}
-
-
- )
- }
+ function renderIcon(listItem) {
return (
-
- No data yet
-
+
)
}
- renderContent() {
- if (this.state.referrers) {
- return (
-
- {this.renderList()}
-
-
- )
- }
- }
-
- render() {
- return (
-
-
- Top Referrers
- {this.state.loading && }
-
- {this.renderContent()}
-
-
-
- )
- }
+ return (
+
+
Top Referrers
+
+
+ )
}
diff --git a/assets/js/dashboard/stats/sources/source-list.js b/assets/js/dashboard/stats/sources/source-list.js
index 96be9ec08..8f918dafc 100644
--- a/assets/js/dashboard/stats/sources/source-list.js
+++ b/assets/js/dashboard/stats/sources/source-list.js
@@ -1,304 +1,108 @@
-import React from 'react';
-import { Link } from 'react-router-dom'
-import FlipMove from 'react-flip-move';
+import React, { Fragment, useState } from 'react';
import * as storage from '../../util/storage'
-import FadeIn from '../../fade-in'
-import Bar from '../bar'
-import MoreLink from '../more-link'
-import numberFormatter from '../../util/number-formatter'
-import * as api from '../../api'
import * as url from '../../util/url'
-import LazyLoader from '../../components/lazy-loader'
-
-class AllSources extends React.Component {
- constructor(props) {
- super(props)
- this.onVisible = this.onVisible.bind(this)
- this.fetchReferrers = this.fetchReferrers.bind(this)
- this.state = { loading: true }
- }
-
- onVisible() {
- this.fetchReferrers()
- if (this.props.query.period === 'realtime') {
- document.addEventListener('tick', this.fetchReferrers)
- }
- }
-
- componentDidUpdate(prevProps) {
- if (this.props.query !== prevProps.query) {
- this.setState({ loading: true, referrers: null })
- this.fetchReferrers()
- }
- }
-
- componentWillUnmount() {
- document.removeEventListener('tick', this.fetchReferrers)
- }
-
- showConversionRate() {
- return !!this.props.query.filters.goal
- }
-
- fetchReferrers() {
- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/sources`, this.props.query)
- .then((res) => this.setState({ loading: false, referrers: res }))
- }
-
- renderReferrer(referrer) {
- const maxWidthDeduction = this.showConversionRate() ? "10rem" : "5rem"
-
- return (
-
-
-
-
-
- {referrer.name}
-
-
-
-
{numberFormatter(referrer.visitors)}
- {this.showConversionRate() &&
{referrer.conversion_rate}%}
-
- )
- }
-
- label() {
- if (this.props.query.period === 'realtime') {
- return 'Current visitors'
- }
-
- if (this.showConversionRate()) {
- return 'Conversions'
- }
-
- return 'Visitors'
- }
-
- renderList() {
- if (this.state.referrers && this.state.referrers.length > 0) {
- return (
-
-
-
Source
-
- {this.label()}
- {this.showConversionRate() && CR}
-
-
-
-
- {this.state.referrers.map(this.renderReferrer.bind(this))}
-
-
-
- )
- } else {
- return No data yet
- }
- }
-
- render() {
- return (
-
-
-
-
Top Sources
- {this.props.renderTabs()}
-
- {this.state.loading && }
-
- {this.renderList()}
-
-
-
- )
- }
-}
+import * as api from '../../api'
+import ListReport from '../reports/list'
+import { VISITORS_METRIC, maybeWithCR } from '../reports/metrics';
+import { Menu, Transition } from '@headlessui/react'
+import { ChevronDownIcon } from '@heroicons/react/20/solid'
+import classNames from 'classnames'
const UTM_TAGS = {
- utm_medium: { label: 'UTM Medium', shortLabel: 'UTM Medium', endpoint: 'utm_mediums' },
- utm_source: { label: 'UTM Source', shortLabel: 'UTM Source', endpoint: 'utm_sources' },
- utm_campaign: { label: 'UTM Campaign', shortLabel: 'UTM Campai', endpoint: 'utm_campaigns' },
- utm_content: { label: 'UTM Content', shortLabel: 'UTM Conten', endpoint: 'utm_contents' },
- utm_term: { label: 'UTM Term', shortLabel: 'UTM Term', endpoint: 'utm_terms' },
+ utm_medium: { label: 'UTM Medium', shortLabel: 'UTM Medium', endpoint: '/utm_mediums' },
+ utm_source: { label: 'UTM Source', shortLabel: 'UTM Source', endpoint: '/utm_sources' },
+ utm_campaign: { label: 'UTM Campaign', shortLabel: 'UTM Campai', endpoint: '/utm_campaigns' },
+ utm_content: { label: 'UTM Content', shortLabel: 'UTM Conten', endpoint: '/utm_contents' },
+ utm_term: { label: 'UTM Term', shortLabel: 'UTM Term', endpoint: '/utm_terms' },
}
-class UTMSources extends React.Component {
- constructor(props) {
- super(props)
- this.onVisible = this.onVisible.bind(this)
- this.fetchReferrers = this.fetchReferrers.bind(this)
- this.state = { loading: true }
- }
-
- onVisible() {
- this.fetchReferrers()
- if (this.props.query.period === 'realtime') {
- document.addEventListener('tick', this.fetchReferrers)
- }
- }
-
- componentDidUpdate(prevProps) {
- if (this.props.query !== prevProps.query || this.props.tab !== prevProps.tab) {
- this.setState({ loading: true, referrers: null })
- this.fetchReferrers()
- }
- }
-
- componentWillUnmount() {
- document.removeEventListener('tick', this.fetchReferrers)
- }
-
- showNoRef() {
- return this.props.query.period === 'realtime'
- }
+function AllSources(props) {
+ const {site, query} = props
- showConversionRate() {
- return !!this.props.query.filters.goal
+ function fetchData() {
+ return api.get(url.apiPath(site, '/sources'), query, {limit: 9})
}
- fetchReferrers() {
- const endpoint = UTM_TAGS[this.props.tab].endpoint
- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/${endpoint}`, this.props.query)
- .then((res) => this.setState({ loading: false, referrers: res }))
+ function getFilterFor(listItem) {
+ return { source: listItem['name']}
}
- renderReferrer(referrer) {
- const maxWidthDeduction = this.showConversionRate() ? "10rem" : "5rem"
-
+ function renderIcon(listItem) {
return (
-
-
-
-
-
- {referrer.name}
-
-
-
- {numberFormatter(referrer.visitors)}
- {this.showConversionRate() && {referrer.conversion_rate}%}
-
+
)
}
- label() {
- if (this.props.query.period === 'realtime') {
- return 'Current visitors'
- }
+ return (
+
+ )
+}
- if (this.showConversionRate()) {
- return 'Conversions'
- }
+function UTMSources(props) {
+ const {site, query} = props
+ const utmTag = UTM_TAGS[props.tab]
- return 'Visitors'
+ function fetchData() {
+ return api.get(url.apiPath(site, utmTag.endpoint), query, {limit: 9})
}
- renderList() {
- if (this.state.referrers && this.state.referrers.length > 0) {
- return (
-
-
-
{UTM_TAGS[this.props.tab].label}
-
- {this.label()}
- {this.showConversionRate() && CR}
-
-
-
-
- {this.state.referrers.map(this.renderReferrer.bind(this))}
-
-
-
- )
- } else {
- return No data yet
- }
+ function getFilterFor(listItem) {
+ return { exit_page: listItem['name']}
}
- render() {
- return (
-
-
-
-
Top Sources
- {this.props.renderTabs()}
-
- {this.state.loading && }
-
- {this.renderList()}
-
-
-
- )
- }
+ return (
+
+ )
}
-import { Fragment } from 'react'
-import { Menu, Transition } from '@headlessui/react'
-import { ChevronDownIcon } from '@heroicons/react/20/solid'
-import classNames from 'classnames'
+export default function SourceList(props) {
+ const {site, query} = props
+ const tabKey = 'sourceTab__' + props.site.domain
+ const storedTab = storage.getItem(tabKey)
+ const [currentTab, setCurrentTab] = useState(storedTab || 'all')
-export default class SourceList extends React.Component {
- constructor(props) {
- super(props)
- this.tabKey = 'sourceTab__' + props.site.domain
- const storedTab = storage.getItem(this.tabKey)
- this.state = {
- tab: storedTab || 'all'
- }
- }
-
- setTab(tab) {
+ function setTab(tab) {
return () => {
- storage.setItem(this.tabKey, tab)
- this.setState({ tab })
+ storage.setItem(tabKey, tab)
+ setCurrentTab(tab)
}
}
- renderTabs() {
+ function renderTabs() {
const activeClass = 'inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold active-prop-heading truncate text-left'
const defaultClass = 'hover:text-indigo-600 cursor-pointer truncate text-left'
const dropdownOptions = Object.keys(UTM_TAGS)
- let buttonText = UTM_TAGS[this.state.tab] ? UTM_TAGS[this.state.tab].label : 'Campaigns'
+ let buttonText = UTM_TAGS[currentTab] ? UTM_TAGS[currentTab].label : 'Campaigns'
return (
-
All
+
All