Launch goals & conversions

This commit is contained in:
Uku Taht 2019-11-28 12:01:07 +08:00
parent 3c35ddae6e
commit 8888c86820
5 changed files with 37 additions and 58 deletions

View File

@ -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

View File

@ -99,9 +99,9 @@
<svg class="w-6 h-6 mr-1 text-indigo" style="transform: translateY(0.3rem);">
<use xlink:href="#feather-check-circle" />
</svg>
<h3 class="inline">Email reports</h3>
<h3 class="inline">Goals & Conversions</h3>
<p class="text-lg mt-2">
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.
</p>
</div>
@ -119,9 +119,9 @@
<svg class="w-6 h-6 mr-1 text-indigo" style="transform: translateY(0.3rem);">
<use xlink:href="#feather-check-circle" />
</svg>
<h3 class="inline">SPA support</h3>
<h3 class="inline">Email reports</h3>
<p class="text-lg mt-2">
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.
</p>
</div>

View File

@ -1,23 +0,0 @@
<%= if get_flash(@conn, :success) do %>
<div id="flash" class="max-w-sm w-full rounded mx-auto text-center bg-green-dark text-green-lightest text-sm font-bold px-4 w-full transition overflow-hidden" role="alert">
<p class="py-3"><%= get_flash(@conn, :success) %></p>
</div>
<% end %>
<div class="max-w-sm w-full mx-auto bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8">
<h2>Goals for <%= @site.domain %></h2>
<div class="my-6">
<%= if Enum.count(@goals) > 0 do %>
<%= for goal <- @goals do %>
<div class="border-b border-grey-light py-3 flex justify-between">
<small class="font-bold"><%= goal_name(goal) %></small>
<%= 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."]) %>
</div>
<% end %>
<% else %>
<div>No goals configured for this site yet</div>
<% end %>
</div>
<%= link("+ Add goal", to: "/#{@site.domain}/goals/new", class: "button mt-4 w-full") %>
</div>

View File

@ -50,6 +50,25 @@
<% end %>
</div>
<div class="max-w-md mx-auto bg-white shadow-md rounded rounded-t-none border-t-2 border-indigo-lightest px-8 pt-6 pb-8 mt-10">
<h2>Goals</h2>
<div class="my-4 border-b border-grey-light"></div>
<div>
<%= if Enum.count(@goals) > 0 do %>
<%= for goal <- @goals do %>
<div class="border-b border-grey-light py-3 flex justify-between">
<small class="font-bold"><%= goal_name(goal) %></small>
<%= 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."]) %>
</div>
<% end %>
<% else %>
<div>No goals configured for this site yet</div>
<% end %>
</div>
<%= link("+ Add goal", to: "/#{@site.domain}/goals/new", class: "button mt-6") %>
</div>
<div class="max-w-md mx-auto bg-white shadow-md rounded rounded-t-none border-t-2 border-indigo-lightest px-8 pt-6 pb-8 mt-10" id="google-auth">
<div class="flex items-center justify-between">
<h2>Google Integration</h2>

View File

@ -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]