mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 09:01:40 +03:00
0541098330
* refactor ListReport Pass a 'getFilterFor' function instead of a 'filter' object to ListReport * Keep the statsBoxClass in one place only * add classname prop to MoreLink * define metric structs as ListReport inputs * Fix a bug If the query changes, we also want to reset the eventListener function. Otherwise we keep calling an outdated function that fetches old data. * fix CI
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import numberFormatter from "../../util/number-formatter"
|
|
import React from "react"
|
|
|
|
export const VISITORS_METRIC = {
|
|
name: 'visitors',
|
|
label: 'Visitors',
|
|
realtimeLabel: 'Current visitors',
|
|
goalFilterLabel: 'Conversions'
|
|
}
|
|
export const UNIQUE_ENTRANCES_METRIC = {
|
|
...VISITORS_METRIC,
|
|
name: 'unique_entrances',
|
|
label: 'Unique Entrances'
|
|
}
|
|
export const UNIQUE_EXITS_METRIC = {
|
|
...VISITORS_METRIC,
|
|
name: 'unique_exits',
|
|
label: 'Unique Exits'
|
|
}
|
|
export const PERCENTAGE_METRIC = { name: 'percentage', label: '%' }
|
|
export const CR_METRIC = { name: 'conversion_rate', label: 'CR' }
|
|
|
|
export function maybeWithCR(metrics, query) {
|
|
if (metrics.includes(PERCENTAGE_METRIC) && query.filters.goal) {
|
|
return metrics.filter((m) => { return m !== PERCENTAGE_METRIC }).concat([CR_METRIC])
|
|
}
|
|
else if (query.filters.goal) {
|
|
return metrics.concat(CR_METRIC)
|
|
}
|
|
else {
|
|
return metrics
|
|
}
|
|
}
|
|
|
|
export function displayMetricValue(value, metric) {
|
|
if ([PERCENTAGE_METRIC, CR_METRIC].includes(metric)) {
|
|
return `${value}%`
|
|
} else {
|
|
return <span tooltip={value}>{ numberFormatter(value) }</span>
|
|
}
|
|
}
|
|
|
|
export function metricLabelFor(metric, query) {
|
|
if (metric.realtimeLabel && query.period === 'realtime') { return metric.realtimeLabel }
|
|
if (metric.goalFilterLabel && query.filters.goal) { return metric.goalFilterLabel }
|
|
return metric.label
|
|
} |