View Source Plausible.Stats.Util (Plausible v0.0.1)

Utilities for modifying stat results

Summary

Functions

Sometimes we need to manually add metrics in order to calculate the value for other metrics. E.g

This function adds the visitors metric into the list of given metrics if it's not already there and if there is a conversion_rate metric in the list.

Functions

Link to this function

calculate_cr(unique_visitors, converted_visitors)

View Source
Link to this function

keep_requested_metrics(results, requested_metrics)

View Source

Sometimes we need to manually add metrics in order to calculate the value for other metrics. E.g:

  • __internal_visits is fetched when querying bounce rate and visit duration, as it is needed to calculate these from imported data.

  • visitors metric might be added manually via maybe_add_visitors_metric/1, in order to be able to calculate conversion rate.

This function can be used for stripping those metrics from a breakdown (list), or an aggregate (map) result. We do not want to return metrics that we're not requested.

Link to this function

maybe_add_visitors_metric(metrics)

View Source

This function adds the visitors metric into the list of given metrics if it's not already there and if there is a conversion_rate metric in the list.

Currently, the conversion rate cannot be queried from the database with a simple select clause - instead, we need to fetch the database result first, and then manually add it into the aggregate map or every entry of thebreakdown list.

In order for us to be able to calculate it based on the results returned by the database query, the visitors metric needs to be queried.