Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Include imported page paths in pageview goal suggestions (#4193)

Adrian Gruntkowskifd81ef21058f
diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.ex
index 58f498ea04..86b6b16b97 100644
--- a/lib/plausible_web/live/goal_settings.ex
+++ b/lib/plausible_web/live/goal_settings.ex
@@ -16,7 +16,9 @@ defmodule PlausibleWeb.Live.GoalSettings do
socket =
socket
|> assign_new(:site, fn ->
- Sites.get_for_user!(user_id, domain, [:owner, :admin, :super_admin])
+ user_id
+ |> Sites.get_for_user!(domain, [:owner, :admin, :super_admin])
+ |> Plausible.Imported.load_import_data()
end)
|> assign_new(:all_goals, fn %{site: site} ->
Goals.for_site(site, preload_funnels?: true)
diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.ex
index e87959814d..6ba350f7a2 100644
--- a/lib/plausible_web/live/goal_settings/form.ex
+++ b/lib/plausible_web/live/goal_settings/form.ex
@@ -319,7 +319,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
end
def suggest_page_paths(input, _options, site) do
- query = Plausible.Stats.Query.from(site, %{})
+ query = Plausible.Stats.Query.from(site, %{"with_imported" => "true", "period" => "all"})
site
|> Plausible.Stats.filter_suggestions(query, "page", input)
diff --git a/test/plausible_web/live/goal_settings/form_test.exs b/test/plausible_web/live/goal_settings/form_test.exs
index 72664fd635..8bf2959088 100644
--- a/test/plausible_web/live/goal_settings/form_test.exs
+++ b/test/plausible_web/live/goal_settings/form_test.exs
@@ -162,6 +162,30 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest do
assert html =~ "/go/home"
refute html =~ "/go/to/page/1"
end
+
+ test "pageview combo considers imported pageviews as well", %{conn: conn, site: site} do
+ site_import = insert(:site_import, site: site)
+
+ populate_stats(site, site_import.id, [
+ build(:imported_pages, page: "/go/to/page/1", pageviews: 2),
+ build(:imported_pages, page: "/go/home", pageviews: 1)
+ ])
+
+ lv = get_liveview(conn, site)
+ lv |> element(~s/a#pageview-tab/) |> render_click()
+
+ type_into_combo(lv, "page_path_input", "/go/to/p")
+
+ html = render(lv)
+ assert html =~ "Create "/go/to/p""
+ assert html =~ "/go/to/page/1"
+ refute html =~ "/go/home"
+
+ type_into_combo(lv, "page_path_input", "/go/h")
+ html = render(lv)
+ assert html =~ "/go/home"
+ refute html =~ "/go/to/page/1"
+ end
end
defp type_into_combo(lv, id, text) do