analytics/lib/plausible_web/controllers/api
Vini Brasil e4d4f7d954
Revenue tracking: Ingestion and breakdown queries (#2957)
* Add revenue fields to ClickHouse events

This commit adds 4 fields to the ClickHouse events_v2 table:

* `revenue_source_amount` and `revenue_source_currency` store revenue in
  the original currency sent during ingestion

* `revenue_reporting_amount` and `revenue_reporting_currency` store
  revenue in a common currency to perform calculations, and this
  currency is defined by the user when setting up the goal

The type of amount fields is `Nullable(Decimal64(3))`. That covers all
fiat currencies and allows us to store huge amounts. Even though
ClickHouse does not suggest using `Nullable`, this is a good use case,
because otherwise additional work would have to be done to
differentiate missing values from real zeroes.

I ran a benchmark with the data pattern we expect in production, where
we have more missing values than real decimals. I created 100 million
records where 90% of decimals are missing. The difference between the
tables in storage is just 0.4Mb.

* Add revenue parameter to Events API

This commit adds support for sending revenue data in ingestion using the
`revenue` parameter - aliased to `$`.

* Add revenue parameter to mix send_pageview

* Add average and total revenue to breakdown queries
2023-06-12 18:29:17 +01:00
..
external_controller.ex improve transfer ownership error message (#2651) 2023-02-13 15:25:17 +01:00
external_sites_controller.ex Clean up after V2 migration (#2868) 2023-04-24 12:17:57 +02:00
external_stats_controller.ex Enable sampling in the Stats API (#2985) 2023-06-01 15:35:08 +02:00
helpers.ex Block Stats API for locked sites (#2302) 2022-10-04 15:34:45 +03:00
internal_controller.ex Keep track of native stats start timestamp when retrieving data (#2715) 2023-03-01 13:11:31 +01:00
paddle_controller.ex Wrap paddle actions with DB transactions (#2558) 2023-01-03 16:14:50 +01:00
stats_controller.ex Revenue tracking: Ingestion and breakdown queries (#2957) 2023-06-12 18:29:17 +01:00