Stop suggesting pageleave as a custom event goal name (#4829)

* stop suggestions pageleave as a custom event goal name

* add missing test
This commit is contained in:
RobertJoonas 2024-11-18 11:16:33 +01:00 committed by GitHub
parent c2a95a142d
commit 916c2bb4c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View File

@ -44,7 +44,7 @@ defmodule Plausible.Stats.GoalSuggestions do
native_q = native_q =
from(e in base_event_query(site, query), from(e in base_event_query(site, query),
where: fragment("? ilike ?", e.name, ^matches), where: fragment("? ilike ?", e.name, ^matches),
where: e.name != "pageview", where: e.name not in ["pageview", "pageleave"],
where: fragment("trim(?)", e.name) != "", where: fragment("trim(?)", e.name) != "",
where: e.name == fragment("trim(?)", e.name), where: e.name == fragment("trim(?)", e.name),
where: e.name not in ^excluded, where: e.name not in ^excluded,

View File

@ -56,10 +56,14 @@ defmodule Plausible.Stats.GoalSuggestionsTest do
] ]
end end
test "ignores the 'pageview' event name", %{site: site} do test "ignores 'pageview' and 'pageleave' event names", %{site: site} do
populate_stats(site, [ populate_stats(site, [
build(:event, name: "Signup"), build(:event, name: "Signup"),
build(:pageview) build(:pageview,
user_id: 1,
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :minute)
),
build(:event, name: "pageleave", user_id: 1, timestamp: NaiveDateTime.utc_now())
]) ])
assert GoalSuggestions.suggest_event_names(site, "") == ["Signup"] assert GoalSuggestions.suggest_event_names(site, "") == ["Signup"]

View File

@ -50,11 +50,28 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
end end
test "returns suggestions for goals", %{conn: conn, site: site} do test "returns suggestions for goals", %{conn: conn, site: site} do
conn = get(conn, "/api/stats/#{site.domain}/suggestions/goal?period=month&date=2019-01-01") conn =
get(conn, "/api/stats/#{site.domain}/suggestions/goal?period=month&date=2019-01-01&q=")
assert json_response(conn, 200) == [] assert json_response(conn, 200) == []
end end
test "returns suggestions for configured site goals but not all event names", %{
conn: conn,
site: site
} do
insert(:goal, site: site, event_name: "Signup")
populate_stats(site, [
build(:event, name: "Signup", timestamp: ~N[2019-01-01 00:00:00]),
build(:event, name: "another", timestamp: ~N[2019-01-01 00:00:00])
])
conn = get(conn, "/api/stats/#{site.domain}/suggestions/goal?period=day&date=2019-01-01&q=")
assert json_response(conn, 200) == [%{"label" => "Signup", "value" => "Signup"}]
end
test "returns suggestions for sources", %{conn: conn, site: site} do test "returns suggestions for sources", %{conn: conn, site: site} do
populate_stats(site, [ populate_stats(site, [
build(:pageview, timestamp: ~N[2019-01-01 23:00:00], referrer_source: "Bing"), build(:pageview, timestamp: ~N[2019-01-01 23:00:00], referrer_source: "Bing"),