diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 6ac028e55..32c058716 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -33,19 +33,6 @@ defmodule PlausibleWeb.SiteController do |> render("snippet.html", site: site, layout: {PlausibleWeb.LayoutView, "focus.html"}) end - def goals(conn, %{"website" => website}) do - site = Sites.get_for_user!(conn.assigns[:current_user].id, website) - goals = Goals.for_site(site.domain) - - conn - |> assign(:skip_plausible_tracking, true) - |> render("goal_settings.html", - site: site, - goals: goals, - layout: {PlausibleWeb.LayoutView, "focus.html"} - ) - end - def new_goal(conn, %{"website" => website}) do site = Sites.get_for_user!(conn.assigns[:current_user].id, website) changeset = Plausible.Goal.changeset(%Plausible.Goal{}) @@ -66,7 +53,7 @@ defmodule PlausibleWeb.SiteController do {:ok, _} -> conn |> put_flash(:success, "Goal created succesfully") - |> redirect(to: "/#{website}/goals") + |> redirect(to: "/#{website}/settings") {:error, :goal, changeset, _} -> conn |> assign(:skip_plausible_tracking, true) @@ -83,7 +70,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Goal deleted succesfully") - |> redirect(to: "/#{website}/goals") + |> redirect(to: "/#{website}/settings") end def settings(conn, %{"website" => website}) do @@ -98,6 +85,7 @@ defmodule PlausibleWeb.SiteController do weekly_report_changeset = weekly_report && Plausible.Site.WeeklyReport.changeset(weekly_report, %{}) monthly_report = Repo.get_by(Plausible.Site.MonthlyReport, site_id: site.id) monthly_report_changeset = monthly_report && Plausible.Site.WeeklyReport.changeset(monthly_report, %{}) + goals = Goals.for_site(site.domain) conn |> assign(:skip_plausible_tracking, true) @@ -106,6 +94,7 @@ defmodule PlausibleWeb.SiteController do weekly_report_changeset: weekly_report_changeset, monthly_report_changeset: monthly_report_changeset, search_console_domains: search_console_domains, + goals: goals, changeset: Plausible.Site.changeset(site, %{}) ) end diff --git a/lib/plausible_web/templates/page/index.html.eex b/lib/plausible_web/templates/page/index.html.eex index cf8f9a127..78f70044c 100644 --- a/lib/plausible_web/templates/page/index.html.eex +++ b/lib/plausible_web/templates/page/index.html.eex @@ -99,9 +99,9 @@ -

Email reports

+

Goals & Conversions

- Keep an eye on your traffic with a weekly email report including pageviews, visitor numbers, top pages and top referrers for the week. + Find out which referrers are driving the most conversions to your site. Works with custom events or page URLs you want your visitors to reach.

@@ -119,9 +119,9 @@ -

SPA support

+

Email reports

- Plausible is built with modern web frameworks in mind and it works automatically with any pushState based router on the frontend. + Keep an eye on your traffic with a weekly email report including pageviews, visitor numbers, top pages and top referrers for the week.

diff --git a/lib/plausible_web/templates/site/goal_settings.html.eex b/lib/plausible_web/templates/site/goal_settings.html.eex deleted file mode 100644 index 0fca28c07..000000000 --- a/lib/plausible_web/templates/site/goal_settings.html.eex +++ /dev/null @@ -1,23 +0,0 @@ -<%= if get_flash(@conn, :success) do %> - -<% end %> - -
-

Goals for <%= @site.domain %>

-
- <%= if Enum.count(@goals) > 0 do %> - <%= for goal <- @goals do %> -
- <%= goal_name(goal) %> - <%= button("❌", to: "/#{@site.domain}/goals/#{goal.id}", method: :delete, class: "text-sm", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) %> -
- <% end %> - <% else %> -
No goals configured for this site yet
- <% end %> -
- - <%= link("+ Add goal", to: "/#{@site.domain}/goals/new", class: "button mt-4 w-full") %> -
diff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eex index af544153e..fd81f9112 100644 --- a/lib/plausible_web/templates/site/settings.html.eex +++ b/lib/plausible_web/templates/site/settings.html.eex @@ -50,6 +50,25 @@ <% end %> +
+

Goals

+
+
+ <%= if Enum.count(@goals) > 0 do %> + <%= for goal <- @goals do %> +
+ <%= goal_name(goal) %> + <%= button("❌", to: "/#{@site.domain}/goals/#{goal.id}", method: :delete, class: "text-sm", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) %> +
+ <% end %> + <% else %> +
No goals configured for this site yet
+ <% end %> +
+ + <%= link("+ Add goal", to: "/#{@site.domain}/goals/new", class: "button mt-6") %> +
+

Google Integration

diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs index 06de2c138..1de730417 100644 --- a/test/plausible_web/controllers/site_controller_test.exs +++ b/test/plausible_web/controllers/site_controller_test.exs @@ -71,6 +71,16 @@ defmodule PlausibleWeb.SiteControllerTest do assert html_response(conn, 200) =~ "Settings" end + + test "lists goals for the site", %{conn: conn, site: site} do + insert(:goal, domain: site.domain, event_name: "Custom event") + insert(:goal, domain: site.domain, page_path: "/register") + + conn = get(conn, "/#{site.domain}/settings") + + assert html_response(conn, 200) =~ "Custom event" + assert html_response(conn, 200) =~ "Visit /register" + end end describe "PUT /:website/settings" do @@ -166,22 +176,6 @@ defmodule PlausibleWeb.SiteControllerTest do end end - describe "GET /:website/goals" do - setup [:create_user, :log_in, :create_site] - - test "lists goals for the site", %{conn: conn, site: site} do - insert(:goal, domain: site.domain, event_name: "Custom event") - insert(:goal, domain: site.domain, page_path: "/register") - - conn = get(conn, "/#{site.domain}/goals") - - - assert html_response(conn, 200) =~ "Goals for " <> site.domain - assert html_response(conn, 200) =~ "Custom event" - assert html_response(conn, 200) =~ "Visit /register" - end - end - describe "DELETE /:website/goals/:id" do setup [:create_user, :log_in, :create_site]