Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Consolidated view settings (#5795)
RobertJoonasd0ba8f7bd069
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/consolidated_views.ex b/extra/lib/plausible_web/live/customer_support/team/components/consolidated_views.exindex a3bbfec2e9..6eb0cbe33a 100644--- a/extra/lib/plausible_web/live/customer_support/team/components/consolidated_views.ex+++ b/extra/lib/plausible_web/live/customer_support/team/components/consolidated_views.ex@@ -90,8 +90,8 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews dosuccess("Consolidated view created"){:noreply, assign(socket, consolidated_views: [consolidated_view])}- {:error, _} ->- failure("Could not create consolidated view")+ {:error, reason} ->+ failure("Could not create consolidated view. Reason: #{inspect(reason)}"){:noreply, socket}endenddiff --git a/lib/plausible/goals/goals.ex b/lib/plausible/goals/goals.exindex 06c84dd8cf..02b9566662 100644--- a/lib/plausible/goals/goals.ex+++ b/lib/plausible/goals/goals.ex@@ -327,6 +327,7 @@ defmodule Plausible.Goals dochangeset = Goal.changeset(%Goal{site_id: site.id}, params)with :ok <- maybe_check_feature_access(site, changeset),+ :ok <- check_no_currency_if_consolidated(site, changeset),{:ok, goal} <- Repo.insert(changeset, insert_opts) do# Upsert with `on_conflict: :nothing` strategy# will result in goal struct missing primary key field@@ -353,6 +354,14 @@ defmodule Plausible.Goals doendend+ defp check_no_currency_if_consolidated(site, changeset) do+ if Plausible.Sites.consolidated?(site) && Ecto.Changeset.get_field(changeset, :currency) do+ {:error, :revenue_goals_unavailable}+ else+ :ok+ end+ end+defp maybe_trim(%Goal{} = goal) do# we make sure that even if we saved goals erroneously with trailing# space, it's removed during fetchdiff --git a/lib/plausible/props.ex b/lib/plausible/props.exindex b462a3a522..749d36e600 100644--- a/lib/plausible/props.ex+++ b/lib/plausible/props.ex@@ -2,7 +2,7 @@ defmodule Plausible.Props do@moduledoc """Context module for handling custom event props."""-+ use Plausibleimport Ecto.Query@type prop :: String.t()@@ -171,7 +171,7 @@ defmodule Plausible.Props dounnested_keys =from e in Plausible.ClickhouseEventV2,- where: e.site_id == ^site.id,+ where: ^site_id_filter(site),where: fragment("? > (NOW() - INTERVAL 6 MONTH)", e.timestamp),select: %{key: fragment("arrayJoin(?)", field(e, :"meta.key"))}@@ -186,6 +186,21 @@ defmodule Plausible.Props do)end+ on_ee do+ defp site_id_filter(%Plausible.Site{} = site) do+ if Plausible.Sites.consolidated?(site) do+ site_ids = Plausible.ConsolidatedView.Cache.get(site.domain)+ dynamic([e], fragment("? in ?", e.site_id, ^site_ids))+ else+ dynamic([e], e.site_id == ^site.id)+ end+ end+ else+ defp site_id_filter(%Plausible.Site{} = site) do+ dynamic([e], e.site_id == ^site.id)+ end+ end+defp valid?(key) doString.length(key) in 1..@max_prop_key_lengthenddiff --git a/lib/plausible/sites.ex b/lib/plausible/sites.exindex df9e132fd3..d7079ac86b 100644--- a/lib/plausible/sites.ex+++ b/lib/plausible/sites.ex@@ -20,10 +20,14 @@ defmodule Plausible.Sites dodef consolidated?(%Site{} = site), do: site.consolidatedelse@spec regular?(Site.t()) :: boolean()- def regular?(%Site{}), do: true+ def regular?(%Site{}), do: always(true)@spec consolidated?(Site.t()) :: boolean()- def consolidated?(%Site{}), do: false+ def consolidated?(%Site{}), do: always(false)+ end++ def display_name(%Site{} = site) do+ if consolidated?(site), do: "consolidated view", else: site.domainend@shared_link_special_names ["WordPress - Shared Dashboard"]diff --git a/lib/plausible/stats/filters/query_parser.ex b/lib/plausible/stats/filters/query_parser.exindex 1f9c75cdab..1187e5c294 100644--- a/lib/plausible/stats/filters/query_parser.ex+++ b/lib/plausible/stats/filters/query_parser.ex@@ -80,7 +80,7 @@ defmodule Plausible.Stats.Filters.QueryParser doon_ee dodef get_consolidated_site_ids(%Plausible.Site{} = site) doif Plausible.Sites.consolidated?(site) do- Plausible.ConsolidatedView.Cache.get(site.team.identifier)+ Plausible.ConsolidatedView.Cache.get(site.domain)endendelsediff --git a/lib/plausible/stats/legacy/legacy_query_builder.ex b/lib/plausible/stats/legacy/legacy_query_builder.exindex b5972d141e..bea576eb67 100644--- a/lib/plausible/stats/legacy/legacy_query_builder.ex+++ b/lib/plausible/stats/legacy/legacy_query_builder.ex@@ -45,7 +45,7 @@ defmodule Plausible.Stats.Legacy.QueryBuilder doon_ee dodefp put_consolidated_site_ids(query, %Plausible.Site{} = site) doif Plausible.Sites.consolidated?(site) do- site_ids = Plausible.ConsolidatedView.Cache.get(site.team.identifier)+ site_ids = Plausible.ConsolidatedView.Cache.get(site.domain)struct!(query, consolidated_site_ids: site_ids)elsequerydiff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.exindex 34eac55db2..45d0c89d87 100644--- a/lib/plausible_web/components/generic.ex+++ b/lib/plausible_web/components/generic.ex@@ -490,7 +490,7 @@ defmodule PlausibleWeb.Components.Generic dodef tile(assigns) do~H"""- <div class="shadow-sm bg-white dark:bg-gray-900 rounded-md mb-6">+ <div data-test-id="settings-tile" class="shadow-sm bg-white dark:bg-gray-900 rounded-md mb-6"><header class="relative py-4 px-6"><.title>{render_slot(@title)}diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex b95c2d092b..91a8c5340a 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -16,7 +16,10 @@ defmodule PlausibleWeb.Live.GoalSettings dosocket|> assign_new(:site, fn %{current_user: current_user} ->current_user- |> Plausible.Sites.get_for_user!(domain, roles: [:owner, :admin, :editor, :super_admin])+ |> Plausible.Sites.get_for_user!(domain,+ roles: [:owner, :admin, :editor, :super_admin],+ include_consolidated?: true+ )end)|> assign_new(:site_role, fn %{site: site, current_user: current_user} ->if Plausible.Auth.is_super_admin?(current_user) dodiff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.exindex b2ff5cc02d..3abcaf53d6 100644--- a/lib/plausible_web/live/goal_settings/form.ex+++ b/lib/plausible_web/live/goal_settings/form.ex@@ -111,7 +111,9 @@ defmodule PlausibleWeb.Live.GoalSettings.Form dophx-submit="save-goal"phx-target={@myself}>- <.title>Add goal for {@domain}</.title>+ <.title>+ Add goal for {Plausible.Sites.display_name(@site)}+ </.title><.tabs current_user={@current_user} site={@site} selected_tab={@selected_tab} myself={@myself} />@@ -376,27 +378,24 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do/></div>- <.revenue_goal_settings- :if={ee?()}- f={@f}- site={@site}- site_role={@site_role}- site_team={@site_team}- has_access_to_revenue_goals?={@has_access_to_revenue_goals?}- goal={@goal}- suffix={@suffix}- />+ <%= if ee?() and Plausible.Sites.regular?(@site) and not editing_non_revenue_goal?(assigns) do %>+ <.revenue_goal_settings+ f={@f}+ site={@site}+ site_role={@site_role}+ site_team={@site_team}+ has_access_to_revenue_goals?={@has_access_to_revenue_goals?}+ goal={@goal}+ suffix={@suffix}+ />+ <% else %>+ <div class="h-2"></div>+ <% end %></div></div>"""end- def revenue_goal_settings(%{goal: %{currency: nil}} = assigns) do- ~H"""- <div class="h-2"></div>- """- end-def revenue_goal_settings(assigns) dojs_data =Jason.encode!(%{@@ -407,14 +406,14 @@ defmodule PlausibleWeb.Live.GoalSettings.Form doassigns = assign(assigns, selected_currency: currency_option(assigns.goal), js_data: js_data)~H"""- <div x-data={@js_data}>+ <div x-data={@js_data} data-test-id="revenue-goal-settings"><%= if is_nil(@goal) do %><div class="mt-6 mb-3"><.revenue_toggle {assigns} /></div><% else %><label- data-test="goal-currency-label"+ data-test-id="goal-currency-label"class="mt-4 mb-2 text-sm block font-medium dark:text-gray-100">Currency@@ -621,4 +620,14 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do</.tooltip>"""end++ on_ee do+ defp editing_non_revenue_goal?(%{goal: nil} = _assigns), do: false++ defp editing_non_revenue_goal?(%{goal: goal} = _assigns) do+ not Plausible.Goal.Revenue.revenue?(goal)+ end+ else+ defp editing_non_revenue_goal?(_assigns), do: false+ endenddiff --git a/lib/plausible_web/live/props_settings.ex b/lib/plausible_web/live/props_settings.exindex bfe48544e2..1a65a9ed78 100644--- a/lib/plausible_web/live/props_settings.ex+++ b/lib/plausible_web/live/props_settings.ex@@ -17,7 +17,8 @@ defmodule PlausibleWeb.Live.PropsSettings do:admin,:editor,:super_admin- ]+ ],+ include_consolidated?: true)end)|> assign_new(:all_props, fn %{site: site} ->diff --git a/lib/plausible_web/live/props_settings/form.ex b/lib/plausible_web/live/props_settings/form.exindex 88aa5e2966..38ec077b51 100644--- a/lib/plausible_web/live/props_settings/form.ex+++ b/lib/plausible_web/live/props_settings/form.ex@@ -24,7 +24,8 @@ defmodule PlausibleWeb.Live.PropsSettings.Form do:admin,:editor,:super_admin- ]+ ],+ include_consolidated?: true)end)|> assign_new(:form, fn %{site: site} ->@@ -56,7 +57,9 @@ defmodule PlausibleWeb.Live.PropsSettings.Form dophx-submit="allow-prop"phx-click-away="cancel-allow-prop">- <.title>Add property for {@domain}</.title>+ <.title>+ Add property for {Plausible.Sites.display_name(@site)}+ </.title><div class="mt-6"><.label for="prop_input">diff --git a/lib/plausible_web/templates/layout/site_settings.html.heex b/lib/plausible_web/templates/layout/site_settings.html.heexindex f8711180db..c9b57bacaa 100644--- a/lib/plausible_web/templates/layout/site_settings.html.heex+++ b/lib/plausible_web/templates/layout/site_settings.html.heex@@ -8,7 +8,7 @@</.styled_link><div class="pb-5 border-b border-gray-200 dark:border-gray-750"><h2 class="text-2xl font-bold leading-7 text-gray-900 dark:text-gray-100 sm:text-3xl sm:leading-9 sm:truncate">- Settings for {@site.domain}+ Settings for {Plausible.Sites.display_name(@site)}</h2></div><div class="lg:grid lg:grid-cols-12 lg:gap-x-5 lg:mt-4">diff --git a/lib/plausible_web/templates/site/settings_general.html.heex b/lib/plausible_web/templates/site/settings_general.html.heexindex c5228df23d..61fbc55fac 100644--- a/lib/plausible_web/templates/site/settings_general.html.heex+++ b/lib/plausible_web/templates/site/settings_general.html.heex@@ -1,5 +1,5 @@<.settings_tiles>- <.tile docs="change-domain-name">+ <.tile :if={Plausible.Sites.regular?(@site)} docs="change-domain-name"><:title>Site domain</:title>@@ -30,7 +30,7 @@</.button></.form></.tile>- <.tile docs="plausible-script">+ <.tile :if={Plausible.Sites.regular?(@site)} docs="plausible-script"><:title>Site installation</:title><:subtitle>Control what data is collected and verify your installation.diff --git a/lib/plausible_web/templates/site/settings_goals.html.heex b/lib/plausible_web/templates/site/settings_goals.html.heexindex 8b58b585cd..309295d036 100644--- a/lib/plausible_web/templates/site/settings_goals.html.heex+++ b/lib/plausible_web/templates/site/settings_goals.html.heex@@ -13,7 +13,7 @@<p>Define actions that you want your users to take, like visiting a certain page, submitting a form, etc.</p>- <p :if={ee?()}>+ <p :if={ee?() and Plausible.Sites.regular?(@site)} data-test-id="setup-funnels-cta">You can also<.styled_link href={Routes.site_path(@conn, :settings_funnels, @site.domain)}>compose goals into funnels.diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 208664252e..32b471a4a1 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -52,29 +52,43 @@ defmodule PlausibleWeb.LayoutView doenddef site_settings_sidebar(conn) do+ regular_site? = Plausible.Sites.regular?(conn.assigns.site)+[%{key: "General", value: "general", icon: :rocket_launch},- %{key: "People", value: "people", icon: :users},- %{key: "Visibility", value: "visibility", icon: :eye},+ if regular_site? do+ %{key: "People", value: "people", icon: :users}+ end,+ if regular_site? do+ %{key: "Visibility", value: "visibility", icon: :eye}+ end,%{key: "Goals", value: "goals", icon: :check_circle},on_ee do- %{key: "Funnels", value: "funnels", icon: :funnel}+ if regular_site? do+ %{key: "Funnels", value: "funnels", icon: :funnel}+ endend,%{key: "Custom properties", value: "properties", icon: :document_text},- %{key: "Integrations", value: "integrations", icon: :puzzle_piece},- %{key: "Imports & exports", value: "imports-exports", icon: :arrow_down_tray},- %{- key: "Shields",- icon: :shield_exclamation,- value: [- %{key: "IP addresses", value: "shields/ip_addresses"},- %{key: "Countries", value: "shields/countries"},- %{key: "Pages", value: "shields/pages"},- %{key: "Hostnames", value: "shields/hostnames"}- ]- },+ if regular_site? do+ %{key: "Integrations", value: "integrations", icon: :puzzle_piece}+ end,+ if regular_site? do+ %{key: "Imports & exports", value: "imports-exports", icon: :arrow_down_tray}+ end,+ if regular_site? do+ %{+ key: "Shields",+ icon: :shield_exclamation,+ value: [+ %{key: "IP addresses", value: "shields/ip_addresses"},+ %{key: "Countries", value: "shields/countries"},+ %{key: "Pages", value: "shields/pages"},+ %{key: "Hostnames", value: "shields/hostnames"}+ ]+ }+ end,%{key: "Email reports", value: "email-reports", icon: :envelope},- if conn.assigns[:site_role] in [:owner, :admin] do+ if regular_site? and conn.assigns[:site_role] in [:owner, :admin] do%{key: "Danger zone", value: "danger-zone", icon: :exclamation_triangle}end]diff --git a/test/plausible/goals_test.exs b/test/plausible/goals_test.exsindex 3458e4e2a4..fe50aed4bb 100644--- a/test/plausible/goals_test.exs+++ b/test/plausible/goals_test.exs@@ -163,6 +163,19 @@ defmodule Plausible.GoalsTest doGoals.create(site, %{"event_name" => "Purchase", "currency" => "EUR"})end+ on_ee do+ test "create/2 returns error when creating a revenue goal for consolidated view" do+ user = new_user()+ new_site(owner: user)+ new_site(owner: user)+ {:ok, team} = Plausible.Teams.get_or_create(user)+ site = new_consolidated_view(team)++ {:error, :revenue_goals_unavailable} =+ Goals.create(site, %{"event_name" => "Purchase", "currency" => "EUR"})+ end+ end+@tag :ee_onlytest "create/2 fails for unknown currency code" dosite = new_site()diff --git a/test/plausible/props_test.exs b/test/plausible/props_test.exsindex 9bd749f4e5..3f3480502d 100644--- a/test/plausible/props_test.exs+++ b/test/plausible/props_test.exs@@ -258,6 +258,26 @@ defmodule Plausible.PropsTest dosite |> Plausible.Props.suggest_keys_to_allow() |> Enum.sort()end+ on_ee do+ test "suggest_keys_to_allow/2 for consolidated view queries events across all included sites" do+ {:ok, team} = new_user() |> Plausible.Teams.get_or_create()+ site1 = new_site(team: team)+ site2 = new_site(team: team)+ consolidated_view = new_consolidated_view(team)++ populate_stats(site1, [+ build(:pageview, "meta.key": ["a", "b"], "meta.value": ["A", "B"])+ ])++ populate_stats(site2, [+ build(:pageview, "meta.key": ["a", "c"], "meta.value": ["A", "C"])+ ])++ assert ["a", "b", "c"] ==+ Plausible.Props.suggest_keys_to_allow(consolidated_view) |> Enum.sort()+ end+ end+test "suggest_keys_to_allow/2 does not return internal prop keys from special event types" dosite = new_site()diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 33928903ee..b57d5db186 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -492,6 +492,7 @@ defmodule PlausibleWeb.SiteControllerTest doconn = get(conn, Routes.site_path(conn, :settings_general, site.domain))resp = html_response(conn, 200)+ assert resp =~ "Settings for #{site.domain}"assert resp =~ "Site domain"assert resp =~ "Change domain"assert resp =~ Routes.site_path(conn, :change_domain, site.domain)@@ -501,6 +502,17 @@ defmodule PlausibleWeb.SiteControllerTest doassert resp =~ "Site installation"end+ on_ee do+ test "renders only timezone section for a consolidated site", %{conn: conn, user: user} do+ consolidated_view = user |> team_of() |> new_consolidated_view()+ conn = get(conn, "/#{consolidated_view.domain}/settings/general")+ resp = html_response(conn, 200)++ assert [tile_element] = find(resp, ~s|div[data-test-id="settings-tile"]|) |> Enum.into([])+ assert text(tile_element) =~ "Site timezone"+ end+ end+@tag :ee_onlytest "all site settings sidebar items are working links", %{conn: conn,@@ -566,6 +578,32 @@ defmodule PlausibleWeb.SiteControllerTest do]end+ on_ee do+ test "consolidated view settings sidebar items", %{+ conn: conn,+ user: user+ } do+ team = user |> team_of()+ site = new_consolidated_view(team)+ conn = get(conn, "/#{site.domain}/settings/general")+ resp = html_response(conn, 200)++ items =+ resp+ |> find("[data-testid=site_settings_sidebar] a")+ |> Enum.map(fn a -> {text(a), text_of_attr(a, "href")} end)++ assert resp =~ "Settings for consolidated view"++ assert items == [+ {"General", "/#{site.domain}/settings/general"},+ {"Goals", "/#{site.domain}/settings/goals"},+ {"Custom properties", "/#{site.domain}/settings/properties"},+ {"Email reports", "/#{site.domain}/settings/email-reports"}+ ]+ end+ end+test "header and footer are shown", %{conn: conn, site: site, user: user} doconn = get(conn, "/#{site.domain}/settings/general")resp = html_response(conn, 200)diff --git a/test/plausible_web/live/goal_settings/form_test.exs b/test/plausible_web/live/goal_settings/form_test.exsindex 0a6de0bdfb..1910bb54d5 100644--- a/test/plausible_web/live/goal_settings/form_test.exs+++ b/test/plausible_web/live/goal_settings/form_test.exs@@ -3,6 +3,12 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest doimport Phoenix.LiveViewTestimport Plausible.Test.Support.HTML+ on_ee do+ import Plausible.Teams.Test+ end++ @revenue_goal_settings ~s|div[data-test-id="revenue-goal-settings"]|+describe "integration - live rendering" dosetup [:create_user, :log_in, :create_site]@@ -12,6 +18,7 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest dohtml = lv |> render()+ assert html =~ "Add goal for #{site.domain}"assert element_exists?(html, ~s/a#pageview-tab/)assert element_exists?(html, ~s/a#event-tab/)@@ -122,11 +129,36 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest doassert html =~ "Custom Event"end+ on_ee do+ test "creates a custom event for consolidated view (revenue switch not available)", %{+ conn: conn,+ user: user+ } do+ {:ok, team} = Plausible.Teams.get_or_create(user)+ site = new_consolidated_view(team)++ lv = get_liveview(conn, site)++ assert render(lv) =~ "Add goal for consolidated view"+ refute element_exists?(render(lv), @revenue_goal_settings)++ lv+ |> element("#goals-form-modalseq0 form")+ |> render_submit(%{goal: %{event_name: "SampleCustomEvent"}})++ html = render(lv)+ assert html =~ "SampleCustomEvent"+ assert html =~ "Custom Event"+ end+ end+@tag :ee_onlytest "creates a revenue goal", %{conn: conn, site: site} dolv = get_liveview(conn, site)refute render(lv) =~ "SampleRevenueGoal"+ assert element_exists?(render(lv), @revenue_goal_settings)+lv|> element("#goals-form-modalseq0 form")|> render_submit(%{@@ -192,7 +224,7 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest dorefute element_exists?(html, "#pageviews-form")assert element_exists?(html, "#custom-events-form")- assert element_exists?(html, ~s/[data-test=goal-currency-label]/)+ assert element_exists?(html, ~s/[data-test-id=goal-currency-label]/)endtest "updates a custom event", %{conn: conn, site: site} dodiff --git a/test/plausible_web/live/goal_settings_test.exs b/test/plausible_web/live/goal_settings_test.exsindex 060ed21ce7..aa4d6a6fe7 100644--- a/test/plausible_web/live/goal_settings_test.exs+++ b/test/plausible_web/live/goal_settings_test.exs@@ -4,6 +4,8 @@ defmodule PlausibleWeb.Live.GoalSettingsTest doimport Phoenix.LiveViewTestimport Plausible.Test.Support.HTML+ @funnels_cta ~s|p[data-test-id="setup-funnels-cta"]|+describe "GET /:domain/settings/goals" dosetup [:create_user, :log_in, :create_site]@@ -14,8 +16,11 @@ defmodule PlausibleWeb.Live.GoalSettingsTest doresp = html_response(conn, 200)assert resp =~ "Define actions that you want your users to take"- assert resp =~ "compose goals into funnels"- assert resp =~ "/#{URI.encode_www_form(site.domain)}/settings/funnels"+ assert text_of_element(resp, @funnels_cta) =~ "compose goals into funnels"++ assert text_of_attr(resp, "#{@funnels_cta} a", "href") =~+ "/#{URI.encode_www_form(site.domain)}/settings/funnels"+assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)assert resp =~ to_string(g1)@@ -98,6 +103,51 @@ defmodule PlausibleWeb.Live.GoalSettingsTest doendend+ on_ee do+ describe "GET /:domain/settings/goals - consolidated views" do+ setup [:create_user, :create_team, :log_in]++ setup %{team: team} = context do+ new_site(team: team)+ new_site(team: team)++ {:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}+ end++ test "no goals exist", %{conn: conn, consolidated_view: consolidated_view} do+ conn = get(conn, "/#{consolidated_view.domain}/settings/goals")++ assert resp = html_response(conn, 200)+ assert resp =~ "Define actions that you want your users to take"+ assert resp =~ "No goals configured for this site"+ assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)+ end++ test "lists goals", %{conn: conn, consolidated_view: consolidated_view} do+ {:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})+ {:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})++ conn = get(conn, "/#{consolidated_view.domain}/settings/goals")++ assert resp = html_response(conn, 200)+ assert resp =~ "Define actions that you want your users to take"+ assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)++ assert resp =~ to_string(g1)+ assert resp =~ "Pageview"+ assert resp =~ to_string(g2)+ assert resp =~ "Custom Event"+ end++ test "does not render funnels cta", %{conn: conn, consolidated_view: consolidated_view} do+ conn = get(conn, "/#{consolidated_view.domain}/settings/goals")++ assert resp = html_response(conn, 200)+ refute element_exists?(resp, @funnels_cta)+ end+ end+ end+describe "GoalSettings live view" dosetup [:create_user, :log_in, :create_site]@@ -213,6 +263,53 @@ defmodule PlausibleWeb.Live.GoalSettingsTest doendend+ on_ee do+ describe "GoalSettings live view - consolidated views" do+ setup [:create_user, :create_team, :log_in]++ setup %{team: team} = context do+ new_site(team: team)+ new_site(team: team)++ {:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}+ end++ test "allows goal deletion", %{conn: conn, consolidated_view: consolidated_view} do+ {:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})+ {:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})++ {lv, html} = get_liveview(conn, consolidated_view, with_html?: true)++ assert html =~ to_string(g1)+ assert html =~ to_string(g2)++ html = lv |> element(~s/button#delete-goal-#{g1.id}/) |> render_click()++ refute html =~ to_string(g1)+ assert html =~ to_string(g2)++ html = get(conn, "/#{consolidated_view.domain}/settings/goals") |> html_response(200)++ refute html =~ to_string(g1)+ assert html =~ to_string(g2)+ end++ test "allows list filtering / search", %{conn: conn, consolidated_view: consolidated_view} do+ {:ok, g1} = Plausible.Goals.create(consolidated_view, %{"page_path" => "/go/to/blog/**"})+ {:ok, g2} = Plausible.Goals.create(consolidated_view, %{"event_name" => "Register"})+ {lv, html} = get_liveview(conn, consolidated_view, with_html?: true)++ assert html =~ to_string(g1)+ assert html =~ to_string(g2)++ html = type_into_search(lv, to_string(g2))++ refute html =~ to_string(g1)+ assert html =~ to_string(g2)+ end+ end+ end+defp setup_goals(site) do{:ok, g1} = Plausible.Goals.create(site, %{"page_path" => "/go/to/blog/**"}){:ok, g2} = Plausible.Goals.create(site, %{"event_name" => "Register"})diff --git a/test/plausible_web/live/props_settings/form_test.exs b/test/plausible_web/live/props_settings/form_test.exsindex e740310481..7628d4d28d 100644--- a/test/plausible_web/live/props_settings/form_test.exs+++ b/test/plausible_web/live/props_settings/form_test.exs@@ -3,6 +3,10 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest doimport Phoenix.LiveViewTestimport Plausible.Test.Support.HTML+ on_ee do+ import Plausible.Teams.Test+ end+describe "Props submission" dosetup [:create_user, :log_in, :create_site]@@ -110,6 +114,75 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest doendend+ on_ee do+ describe "Props submission for consolidated views" do+ setup [:create_user, :create_team, :log_in]++ setup %{team: team} = context do+ new_site(team: team)+ new_site(team: team)++ {:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}+ end++ test "renders form fields", %{conn: conn, consolidated_view: consolidated_view} do+ lv = get_liveview(conn, consolidated_view)+ html = render(lv)++ assert html =~ "Add property for consolidated view"+ assert element_exists?(html, "form input[type=text][name=display-prop_input]")+ assert element_exists?(html, "form input[type=hidden][name=prop]")+ end++ test "allowing a single property", %{conn: conn, consolidated_view: consolidated_view} do+ {parent, lv} = get_liveview(conn, consolidated_view, with_parent?: true)+ refute render(parent) =~ "foobarbaz"+ lv |> element("form") |> render_submit(%{prop: "foobarbaz"})+ parent_html = render(parent)+ assert text_of_element(parent_html, "#prop-0") == "foobarbaz"++ consolidated_view = Plausible.Repo.reload!(consolidated_view)+ assert consolidated_view.allowed_event_props == ["foobarbaz"]+ end++ test "allowing existing properties", %{conn: conn, consolidated_view: consolidated_view} do+ {:ok, site_ids} = Plausible.ConsolidatedView.site_ids(consolidated_view.domain)+ [site1, site2] = Enum.map(site_ids, &Plausible.Repo.get(Plausible.Site, &1))++ populate_stats(site1, [+ build(:pageview, "meta.key": ["a"], "meta.value": ["a"]),+ build(:pageview, "meta.key": ["b"], "meta.value": ["b"])+ ])++ populate_stats(site2, [+ build(:pageview, "meta.key": ["c"], "meta.value": ["c"])+ ])++ list_item_selectors = ["#prop-0", "#prop-1", "#prop-2"]++ {parent, lv} = get_liveview(conn, consolidated_view, with_parent?: true)+ parent_html = render(parent)++ Enum.each(list_item_selectors, fn list_item ->+ refute element_exists?(parent_html, list_item)+ end)++ lv+ |> element(~s/button[phx-click="allow-existing-props"]/)+ |> render_click()++ parent_html = render(parent)++ allowed_props = Enum.map(list_item_selectors, &text_of_element(parent_html, &1))++ assert Enum.sort(allowed_props) == ["a", "b", "c"]++ consolidated_view = Plausible.Repo.reload!(consolidated_view)+ assert Enum.sort(consolidated_view.allowed_event_props) == ["a", "b", "c"]+ end+ end+ end+defp seed_props(%{site: site}) dopopulate_stats(site, [build(:event,diff --git a/test/plausible_web/live/props_settings_test.exs b/test/plausible_web/live/props_settings_test.exsindex 71a9463e2d..18b990b947 100644--- a/test/plausible_web/live/props_settings_test.exs+++ b/test/plausible_web/live/props_settings_test.exs@@ -102,6 +102,62 @@ defmodule PlausibleWeb.Live.PropsSettingsTest doendend+ on_ee do+ describe "GET /:domain/settings/properties - consolidated views" do+ setup [:create_user, :create_team, :log_in]++ setup %{team: team} = context do+ new_site(team: team)+ new_site(team: team)++ {:ok, Map.put(context, :consolidated_view, new_consolidated_view(team))}+ end++ test "lists existing props and renders links", %{+ conn: conn,+ consolidated_view: consolidated_view+ } do+ {:ok, consolidated_view} =+ Plausible.Props.allow(consolidated_view, ["amount", "logged_in", "is_customer"])++ conn = get(conn, "/#{consolidated_view.domain}/settings/properties")++ resp = html_response(conn, 200)+ assert resp =~ "Attach custom properties"++ assert element_exists?(+ resp,+ ~s|a[href="https://plausible.io/docs/custom-props/introduction"]|+ )++ assert resp =~ "amount"+ assert resp =~ "logged_in"+ assert resp =~ "is_customer"+ refute resp =~ "please upgrade your subscription"+ end++ test "if no props are allowed, a proper info is displayed", %{+ conn: conn,+ consolidated_view: consolidated_view+ } do+ conn = get(conn, "/#{consolidated_view.domain}/settings/properties")+ resp = html_response(conn, 200)+ assert resp =~ "No properties configured for this site"+ end++ test "add property button and search input are rendered", %{+ conn: conn,+ consolidated_view: consolidated_view+ } do+ conn = get(conn, "/#{consolidated_view.domain}/settings/properties")+ resp = html_response(conn, 200)+ assert element_exists?(resp, ~s/button[phx-click="add-prop"]/)+ assert element_exists?(resp, ~s/input[type="text"]#filter-text/)+ assert element_exists?(resp, ~s/form[phx-change="filter"]#filter-form/)+ end+ end+ end+# validating input# clicking suggestions fills out input# adding props