Skip to content

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

skip verification in ce (#4604)

ruslandoga71fa38709f5c
diff --git a/lib/plausible_web/live/verification.ex b/lib/plausible_web/live/verification.ex
index e0de7ed565..47b88621b0 100644
--- a/lib/plausible_web/live/verification.ex
+++ b/lib/plausible_web/live/verification.ex
@@ -1,9 +1,10 @@
defmodule PlausibleWeb.Live.Verification do
@moduledoc """
LiveView coordinating the site verification process.
- Onboarding new sites, renders a standalone component.
+ Onboarding new sites, renders a standalone component.
Embedded modal variant is available for general site settings.
"""
+ use Plausible
use PlausibleWeb, :live_view
use Phoenix.HTML
@@ -28,13 +29,14 @@ defmodule PlausibleWeb.Live.Verification do
private = Map.get(socket.private.connect_info, :private, %{})
super_admin? = Plausible.Auth.is_super_admin?(socket.assigns.current_user)
+ has_pageviews? = has_pageviews?(site)
socket =
assign(socket,
site: site,
super_admin?: super_admin?,
domain: domain,
- has_pageviews?: has_pageviews?(site),
+ has_pageviews?: has_pageviews?,
component: @component,
installation_type: params["installation_type"],
report_to: self(),
@@ -45,28 +47,65 @@ defmodule PlausibleWeb.Live.Verification do
attempts: 0
)
- if connected?(socket) do
- launch_delayed(socket)
+ on_ee do
+ if connected?(socket) do
+ launch_delayed(socket)
+ end
+ end
+
+ on_ee do
+ {:ok, socket}
+ else
+ # on CE we skip the verification process and instead,
+ # we just wait for the first pageview to be recorded
+ socket =
+ if has_pageviews? do
+ redirect_to_stats(socket)
+ else
+ schedule_pageviews_check(socket)
+ end
+
+ {:ok, socket}
end
+ end
- {:ok, socket}
+ on_ee do
+ def render(assigns) do
+ ~H"""
+ <PlausibleWeb.Components.FlowProgress.render flow={@flow} current_step="Verify installation" />
+
+ <.live_component
+ module={@component}
+ installation_type={@installation_type}
+ domain={@domain}
+ id="verification-standalone"
+ attempts={@attempts}
+ flow={@flow}
+ awaiting_first_pageview?={not @has_pageviews?}
+ super_admin?={@super_admin?}
+ />
+ """
+ end
+ else
+ def render(assigns) do
+ ~H"""
+ <PlausibleWeb.Components.FlowProgress.render flow={@flow} current_step="Verify installation" />
+ <.awaiting_pageviews />
+ """
+ end
end
- def render(assigns) do
- ~H"""
- <PlausibleWeb.Components.FlowProgress.render flow={@flow} current_step="Verify installation" />
-
- <.live_component
- module={@component}
- installation_type={@installation_type}
- domain={@domain}
- id="verification-standalone"
- attempts={@attempts}
- flow={@flow}
- awaiting_first_pageview?={not @has_pageviews?}
- super_admin?={@super_admin?}
- />
- """
+ on_ce do
+ defp awaiting_pageviews(assigns) do
+ ~H"""
+ <PlausibleWeb.Components.Generic.focus_box>
+ <div class="flex items-center">
+ <div class="block pulsating-circle"></div>
+ <p class="ml-8">Awaiting your first pageview …</p>
+ </div>
+ </PlausibleWeb.Components.Generic.focus_box>
+ """
+ end
end
def handle_event("launch-verification", _, socket) do
@@ -116,7 +155,7 @@ defmodule PlausibleWeb.Live.Verification do
interpretation = Checks.interpret_diagnostics(state)
if not socket.assigns.has_pageviews? do
- Process.send_after(self(), :check_pageviews, socket.assigns.delay * 2)
+ schedule_pageviews_check(socket)
end
update_component(socket,
@@ -132,17 +171,24 @@ defmodule PlausibleWeb.Live.Verification do
def handle_info(:check_pageviews, socket) do
socket =
if has_pageviews?(socket.assigns.site) do
- redirect(socket,
- external: Routes.stats_url(PlausibleWeb.Endpoint, :stats, socket.assigns.domain, [])
- )
+ redirect_to_stats(socket)
else
- Process.send_after(self(), :check_pageviews, socket.assigns.delay * 2)
- socket
+ schedule_pageviews_check(socket)
end
{:noreply, socket}
end
+ defp schedule_pageviews_check(socket) do
+ Process.send_after(self(), :check_pageviews, socket.assigns.delay * 2)
+ socket
+ end
+
+ defp redirect_to_stats(socket) do
+ stats_url = Routes.stats_url(PlausibleWeb.Endpoint, :stats, socket.assigns.domain, [])
+ redirect(socket, external: stats_url)
+ end
+
defp reset_component(socket) do
update_component(socket,
message: "We're visiting your site to ensure that everything is working",
diff --git a/test/plausible_web/live/verification_test.exs b/test/plausible_web/live/verification_test.exs
index 1d4404264c..c21791d037 100644
--- a/test/plausible_web/live/verification_test.exs
+++ b/test/plausible_web/live/verification_test.exs
@@ -13,6 +13,7 @@ defmodule PlausibleWeb.Live.VerificationTest do
@heading ~s|#progress-indicator h3|
describe "GET /:domain" do
+ @tag :ee_only
test "static verification screen renders", %{conn: conn, site: site} do
resp =
get(conn, conn |> no_slowdown() |> get("/#{site.domain}") |> redirected_to)
@@ -23,9 +24,19 @@ defmodule PlausibleWeb.Live.VerificationTest do
assert resp =~ "Verifying your installation"
end
+
+ @tag :ce_build_only
+ test "static verification screen renders (ce)", %{conn: conn, site: site} do
+ resp =
+ get(conn, conn |> no_slowdown() |> get("/#{site.domain}") |> redirected_to)
+ |> html_response(200)
+
+ assert resp =~ "Awaiting your first pageview …"
+ end
end
describe "LiveView" do
+ @tag :ee_only
test "LiveView mounts", %{conn: conn, site: site} do
stub_fetch_body(200, "")
stub_installation()
@@ -38,6 +49,13 @@ defmodule PlausibleWeb.Live.VerificationTest do
"We're visiting your site to ensure that everything is working"
end
+ @tag :ce_build_only
+ test "LiveView mounts (ce)", %{conn: conn, site: site} do
+ {_, html} = get_lv(conn, site)
+ assert html =~ "Awaiting your first pageview …"
+ end
+
+ @tag :ee_only
test "eventually verifies installation", %{conn: conn, site: site} do
stub_fetch_body(200, source(site.domain))
stub_installation()
@@ -59,6 +77,7 @@ defmodule PlausibleWeb.Live.VerificationTest do
assert html =~ "Awaiting your first pageview"
end
+ @tag :ee_only
test "won't await first pageview if site has pageviews", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview)
@@ -106,6 +125,19 @@ defmodule PlausibleWeb.Live.VerificationTest do
assert_redirect(lv, "http://localhost:8000/#{URI.encode_www_form(site.domain)}/")
end
+ @tag :ce_build_only
+ test "will redirect when first pageview arrives (ce)", %{conn: conn, site: site} do
+ {:ok, lv} = kick_off_live_verification(conn, site)
+
+ html = render(lv)
+ assert text(html) =~ "Awaiting your first pageview …"
+
+ populate_stats(site, [build(:pageview)])
+
+ assert_redirect(lv, "http://localhost:8000/#{URI.encode_www_form(site.domain)}/")
+ end
+
+ @tag :ee_only
test "eventually fails to verify installation", %{conn: conn, site: site} do
stub_fetch_body(200, "")
stub_installation(200, plausible_installed(false))