Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
More datepicker improvements
Uku Tahtd40faf6ec796
diff --git a/Makefile b/Makefileindex 9531ba721d..6f60a3c285 100644--- a/Makefile+++ b/Makefile@@ -24,5 +24,5 @@ dummy_event:-H 'X-Forwarded-For: 127.0.0.1' \-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284' \-H 'Content-Type: text/plain' \- --data-binary '{"n":"pageview","u":"http://dummy.site/very-long-link-this-is-going-to-take-a-while-to-read-very-long-indeed-yes","d":"plausible.io","r":null,"w":1666}' \+ --data-binary '{"n":"pageview","u":"http://dummy.site/very-long-link-this-is-going-to-take-a-while-to-read-very-long-indeed-yes","d":"new-site.com","r":null,"w":1666}' \--compresseddiff --git a/assets/js/dashboard/datepicker.js b/assets/js/dashboard/datepicker.jsindex 88d6404267..4bcd8c1886 100644--- a/assets/js/dashboard/datepicker.js+++ b/assets/js/dashboard/datepicker.js@@ -340,8 +340,8 @@ class DatePicker extends React.Component {{ this.renderLink('month', 'Last month', {date: lastMonth(this.props.site)}) }</div><div className="py-1 border-b border-gray-200 dark:border-gray-500 date-option-group">- {this.renderLink("12mo", "Last 12 months")}{this.renderLink("year", "Year to Date")}+ {this.renderLink("12mo", "Last 12 months")}</div><div className="py-1 date-option-group">{this.renderLink("all", "All time")}diff --git a/assets/js/dashboard/util/date.js b/assets/js/dashboard/util/date.jsindex bb913f0cf7..17771009b7 100644--- a/assets/js/dashboard/util/date.js+++ b/assets/js/dashboard/util/date.js@@ -41,7 +41,7 @@ export function formatYear(date) {}export function formatDay(date) {- var weekday = DAYS_ABBREV[date.getUTCDay()];+ var weekday = DAYS_ABBREV[date.getDay()];if (date.getFullYear() !== (new Date()).getFullYear()) {return `${weekday}, ${date.getDate()} ${formatMonthShort(date)} ${date.getFullYear()}`;} else {diff --git a/lib/plausible/stats/query.ex b/lib/plausible/stats/query.exindex 67f1b2fb89..3cf2efabeb 100644--- a/lib/plausible/stats/query.ex+++ b/lib/plausible/stats/query.ex@@ -187,24 +187,43 @@ defmodule Plausible.Stats.Query doenddef from(site, %{"period" => "all"} = params) do- end_date =- today(site.timezone)- |> Timex.end_of_month()-start_date =site.inserted_at|> Timex.Timezone.convert("UTC")|> Timex.Timezone.convert(site.timezone)- |> Timex.beginning_of_month()+ |> Timex.to_date()- %__MODULE__{- period: "all",- date_range: Date.range(start_date, end_date),- interval: Map.get(params, "interval", "month"),- filters: parse_filters(params),- sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)- }- |> maybe_include_imported(site, params)+ now = today(site.timezone)++ cond do+ Timex.diff(now, start_date, :months) > 0 ->+ from(+ site,+ Map.merge(params, %{+ "period" => "custom",+ "from" => Date.to_iso8601(start_date),+ "to" => Date.to_iso8601(now),+ "interval" => "month"+ })+ )+ |> Map.put(:period, "all")++ Timex.diff(now, start_date, :days) > 0 ->+ from(+ site,+ Map.merge(params, %{+ "period" => "custom",+ "from" => Date.to_iso8601(start_date),+ "to" => Date.to_iso8601(now),+ "interval" => "date"+ })+ )+ |> Map.put(:period, "all")++ true ->+ from(site, Map.merge(params, %{"period" => "day", "date" => "today"}))+ |> Map.put(:period, "all")+ endenddef from(site, %{"period" => "custom", "from" => from, "to" => to} = params) dodiff --git a/test/plausible/stats/query_test.exs b/test/plausible/stats/query_test.exsindex df13edf0b3..fe259dbf83 100644--- a/test/plausible/stats/query_test.exs+++ b/test/plausible/stats/query_test.exs@@ -85,8 +85,38 @@ defmodule Plausible.Stats.QueryTest dosite = Map.put(@site, :timezone, "America/Cancun")q = Query.from(site, %{"period" => "all"})- assert q.date_range.first == ~D[2019-12-01]- assert q.date_range.last == Timex.today("America/Cancun") |> Timex.end_of_month()+ assert q.date_range.first == ~D[2019-12-31]+ assert q.date_range.last == Timex.today("America/Cancun")+ end++ test "all time shows hourly if site is completely new" do+ site = Map.put(@site, :inserted_at, Timex.now())+ q = Query.from(site, %{"period" => "all"})++ assert q.date_range.first == Timex.today()+ assert q.date_range.last == Timex.today()+ assert q.period == "all"+ assert q.interval == "hour"+ end++ test "all time shows daily if site is more than a day old" do+ site = Map.put(@site, :inserted_at, Timex.now() |> Timex.shift(days: -1))+ q = Query.from(site, %{"period" => "all"})++ assert q.date_range.first == Timex.today() |> Timex.shift(days: -1)+ assert q.date_range.last == Timex.today()+ assert q.period == "all"+ assert q.interval == "date"+ end++ test "all time shows monthly if site is more than a month old" do+ site = Map.put(@site, :inserted_at, Timex.now() |> Timex.shift(months: -1))+ q = Query.from(site, %{"period" => "all"})++ assert q.date_range.first == Timex.today() |> Timex.shift(months: -1)+ assert q.date_range.last == Timex.today()+ assert q.period == "all"+ assert q.interval == "month"endtest "defaults to 30 days format" do