Skip to content

Commit

Permalink
Proposal: Remove unique users from dashboard when filtering by goal
Browse files Browse the repository at this point in the history
  • Loading branch information
macobo committed Jan 28, 2025
1 parent dd8e143 commit cebee40
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Removed

- Internal stats API routes no longer support legacy dashboard filter format.
- Dashboard no longer shows "Unique visitors" in top stats when filtering by a goal which used to count all users including ones who didn't complete the goal. "Unique conversions" shows the number of unique visitors who completed the goal.

### Changed

Expand Down
3 changes: 1 addition & 2 deletions lib/plausible_web/controllers/api/stats_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,12 @@ defmodule PlausibleWeb.Api.StatsController do

defp fetch_goal_top_stats(site, query) do
metrics =
[:total_visitors, :visitors, :events, :conversion_rate] ++ @revenue_metrics
[:visitors, :events, :conversion_rate] ++ @revenue_metrics

%{results: results, meta: meta} = Stats.aggregate(site, query, metrics)

top_stats =
[
top_stats_entry(results, "Unique visitors", :total_visitors),
top_stats_entry(results, "Unique conversions", :visitors),
top_stats_entry(results, "Total conversions", :events),
on_ee do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,12 @@ defmodule PlausibleWeb.Api.StatsController.TopStatsTest do
} do
filters = Jason.encode!([[:is, "event:goal", ["Signup"]]])

[unique_visitors, unique_conversions, total_conversions, cr] =
[unique_conversions, total_conversions, cr] =
conn
|> get("/api/stats/#{site.domain}/top-stats?filters=#{filters}")
|> json_response(200)
|> Map.get("top_stats")

assert %{"graph_metric" => "total_visitors"} = unique_visitors
assert %{"graph_metric" => "visitors"} = unique_conversions
assert %{"graph_metric" => "events"} = total_conversions
assert %{"graph_metric" => "conversion_rate"} = cr
Expand Down Expand Up @@ -1307,12 +1306,16 @@ defmodule PlausibleWeb.Api.StatsController.TopStatsTest do
describe "GET /api/stats/top-stats - filtered for goal" do
setup [:create_user, :log_in, :create_site]

test "returns total unique visitors", %{conn: conn, site: site} do
test "returns total and unique conversions", %{conn: conn, site: site} do
insert(:goal, site: site, event_name: "Signup")

populate_stats(site, [
build(:pageview, user_id: @user_id),
build(:pageview, user_id: @user_id),
build(:pageview),
build(:event, name: "Signup")
build(:event, user_id: 1, name: "Signup"),
build(:event, user_id: 1, name: "Signup"),
build(:event, user_id: 2, name: "Signup")
])

filters = Jason.encode!([[:is, "event:goal", ["Signup"]]])
Expand All @@ -1325,7 +1328,11 @@ defmodule PlausibleWeb.Api.StatsController.TopStatsTest do

res = json_response(conn, 200)

assert %{"name" => "Unique visitors", "value" => 3, "graph_metric" => "total_visitors"} in res[
assert %{"name" => "Unique conversions", "value" => 2, "graph_metric" => "visitors"} in res[
"top_stats"
]

assert %{"name" => "Total conversions", "value" => 3, "graph_metric" => "events"} in res[
"top_stats"
]
end
Expand Down

0 comments on commit cebee40

Please sign in to comment.