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

This module provides functions for comparing query periods.

It allows you to compare a given period with a previous period or with the same period from the previous year. For example, you can compare this month's main graph with last month or with the same month from last year.

Summary

Functions

Generates a comparison query based on the source query and comparison mode.

Functions

Link to this function

get_comparison_query(source_query, options)

View Source
@spec get_comparison_query(Plausible.Stats.Query.t(), map()) ::
  Plausible.Stats.Query.t()

Generates a comparison query based on the source query and comparison mode.

Currently only historical periods are supported for comparisons (not realtime and 30m periods).

Options

  • mode (required) - specifies the type of comparison and can be one of the following:

    • "previous_period" - shifts back the query by the same number of days the source query has.

    • "year_over_year" - shifts back the query by 1 year.

    • "custom" - compares the query using a custom date range. See date_range for more details.

  • :date_range - a ISO-8601 date string pair used when mode is "custom".

  • :match_day_of_week - determines whether the comparison query should be adjusted to match the day of the week of the source query. When this option is set to true, the comparison query is shifted to start on the same day of the week as the source query, rather than on the exact same date. For example, if the source query starts on Sunday, January 1st, 2023 and the year_over_year comparison query is configured to match_day_of_week, it will be shifted to start on Sunday, January 2nd, 2022 instead of January 1st. Defaults to false.