* refactor metric validation
* link to the correct docs section
* add the new metric to aggregate API
* explicitly remove __internal_visits
The overall metric selection is well defined by
`Plausible.Stats.Timeseries.empty_row/2`. The only metric that needs
to be removed from the timeseries response is __internal_visits.
This commit also moves the `remove_internal_visits_metric` function to a
new Util module to be used by both breakdown and timeseries.
* add the new metric to timeseries API
* mix format
* add moduledoc to keep credo happy
* convert pages_per_visit to string straight away
* do rounding in db query
* query # of visits with sum(sign) instead
* stop converting pages_per_visit to string
"Session metric `#{invalid_metric}` cannot be queried when using a filter on `#{event_only_filter}`."}
conddo
metric=="pages_per_visit"&&property!=nil->
{:error,"Metric `#{metric}` is not supported in breakdown queries"}
true->
{:error,
"The metric `#{invalid_metric}` is not recognized. Find valid metrics from the documentation: https://plausible.io/docs/stats-api#get-apiv1statsbreakdown"}
end
else
{:ok,Enum.map(metrics,&String.to_atom/1)}
event_only_property?(property)->
{:error,"Session metric `#{metric}` cannot be queried for breakdown by `#{property}`."}
event_only_filter->
{:error,
"Session metric `#{metric}` cannot be queried when using a filter on `#{event_only_filter}`."}
true->
{:ok,metric}
end
end
defpvalidate_metric(metric,_,_)do
{:error,
"The metric `#{metric}` is not recognized. Find valid metrics from the documentation: https://plausible.io/docs/stats-api#metrics"}