Skip to content

Commit

Permalink
Stop suggesting pageleave as a custom event goal name (#4829)
Browse files Browse the repository at this point in the history
* stop suggestions pageleave as a custom event goal name

* add missing test
  • Loading branch information
RobertJoonas authored Nov 18, 2024
1 parent c2a95a1 commit 916c2bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/plausible/stats/goal_suggestions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Plausible.Stats.GoalSuggestions do
native_q =
from(e in base_event_query(site, query),
where: fragment("? ilike ?", e.name, ^matches),
where: e.name != "pageview",
where: e.name not in ["pageview", "pageleave"],
where: fragment("trim(?)", e.name) != "",
where: e.name == fragment("trim(?)", e.name),
where: e.name not in ^excluded,
Expand Down
8 changes: 6 additions & 2 deletions test/plausible/stats/goal_suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ defmodule Plausible.Stats.GoalSuggestionsTest do
]
end

test "ignores the 'pageview' event name", %{site: site} do
test "ignores 'pageview' and 'pageleave' event names", %{site: site} do
populate_stats(site, [
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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,28 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
end

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) == []
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
populate_stats(site, [
build(:pageview, timestamp: ~N[2019-01-01 23:00:00], referrer_source: "Bing"),
Expand Down

0 comments on commit 916c2bb

Please sign in to comment.