From fd81ef21058f8fa8f6d7b9a183f2334c0bb427ae Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Thu, 6 Jun 2024 10:40:48 +0200 Subject: [PATCH] Include imported page paths in pageview goal suggestions (#4193) --- lib/plausible_web/live/goal_settings.ex | 4 +++- lib/plausible_web/live/goal_settings/form.ex | 2 +- .../live/goal_settings/form_test.exs | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.ex index 58f498ea0..86b6b16b9 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 e87959814..6ba350f7a 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 72664fd63..8bf295908 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