diff --git a/assets/js/app.js b/assets/js/app.js index eaad0400b..ac96c343b 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -18,6 +18,13 @@ if (document.querySelectorAll('[data-modal]').length > 0) { new CustomEvent('close-modal', { bubbles: true, detail: e.detail.id }) ) }) + window.addEventListener(`phx:open-modal`, (e) => { + document + .getElementById(e.detail.id) + .dispatchEvent( + new CustomEvent('open-modal', { bubbles: true, detail: e.detail.id }) + ) + }) } const triggers = document.querySelectorAll('[data-dropdown-trigger]') diff --git a/lib/plausible_web/live/components/modal.ex b/lib/plausible_web/live/components/modal.ex index e7d76d65f..eb8103058 100644 --- a/lib/plausible_web/live/components/modal.ex +++ b/lib/plausible_web/live/components/modal.ex @@ -106,6 +106,11 @@ defmodule PlausibleWeb.Live.Components.Modal do end end + @spec open(Phoenix.LiveView.Socket.t(), String.t()) :: Phoenix.LiveView.Socket.t() + def open(socket, id) do + Phoenix.LiveView.push_event(socket, "open-modal", %{id: id}) + end + @spec close(Phoenix.LiveView.Socket.t(), String.t()) :: Phoenix.LiveView.Socket.t() def close(socket, id) do Phoenix.LiveView.push_event(socket, "close-modal", %{id: id}) diff --git a/lib/plausible_web/live/verification.ex b/lib/plausible_web/live/verification.ex index 094524955..de294d85d 100644 --- a/lib/plausible_web/live/verification.ex +++ b/lib/plausible_web/live/verification.ex @@ -34,6 +34,14 @@ defmodule PlausibleWeb.Live.Verification do launch_delayed(socket) end + socket = + if connected?(socket) and !!session["modal?"] and !!session["open_modal?"] do + launch_delayed(socket) + Modal.open(socket, "verification-modal") + else + socket + end + {:ok, socket} end diff --git a/lib/plausible_web/templates/email/drop_notification.html.eex b/lib/plausible_web/templates/email/drop_notification.html.eex index 45a97075d..e6464fee8 100644 --- a/lib/plausible_web/templates/email/drop_notification.html.eex +++ b/lib/plausible_web/templates/email/drop_notification.html.eex @@ -4,6 +4,5 @@ We've recorded <%= @current_visitors %> visitors on <%= link(@site.domain, to: "

View dashboard: <%= link(@dashboard_link, to: @dashboard_link) %>

-Something looks off? Please use our integration testing tool to verify that Plausible has been integrated correctly: -<%= link(@settings_link, to: @settings_link) %> +Something looks off? Please use our <%= link("integration testing tool", to: @settings_link) %> to verify that Plausible has been integrated correctly. <% end %> diff --git a/lib/plausible_web/templates/site/settings_general.html.heex b/lib/plausible_web/templates/site/settings_general.html.heex index 3970e83c7..5b1728236 100644 --- a/lib/plausible_web/templates/site/settings_general.html.heex +++ b/lib/plausible_web/templates/site/settings_general.html.heex @@ -112,6 +112,7 @@
<%= live_render(@conn, PlausibleWeb.Live.Verification, session: %{ + "open_modal?" => !!@conn.params["launch_verification"], "site_id" => @site.id, "domain" => @site.domain, "modal?" => true, diff --git a/lib/workers/traffic_change_notifier.ex b/lib/workers/traffic_change_notifier.ex index 08759db56..195a36a5c 100644 --- a/lib/workers/traffic_change_notifier.ex +++ b/lib/workers/traffic_change_notifier.ex @@ -103,7 +103,9 @@ defmodule Plausible.Workers.TrafficChangeNotifier do if Enum.any?(site.members, &(&1.email == recipient)) do { Routes.stats_url(PlausibleWeb.Endpoint, :stats, site.domain, []), - Routes.site_url(PlausibleWeb.Endpoint, :settings_general, site.domain) + Routes.site_url(PlausibleWeb.Endpoint, :settings_general, site.domain, + launch_verification: true + ) <> "#snippet" } else {nil, nil} diff --git a/test/plausible_web/live/verification_test.exs b/test/plausible_web/live/verification_test.exs index f8e69d909..e6c98b6dd 100644 --- a/test/plausible_web/live/verification_test.exs +++ b/test/plausible_web/live/verification_test.exs @@ -140,6 +140,26 @@ defmodule PlausibleWeb.Live.VerificationTest do assert element_exists?(html, @go_to_dashboard_button) end + test "query launch_verification=true launches the modal", %{conn: conn, site: site} do + stub_fetch_body(200, source(site.domain)) + stub_installation() + + {lv, _html} = get_lv_modal(conn, site, "?launch_verification=true") + + assert html = + eventually(fn -> + html = render(lv) + + { + html =~ "Success!", + html + } + end) + + refute html =~ "Awaiting your first pageview" + assert element_exists?(html, @go_to_dashboard_button) + end + test "failed verification can be retried", %{conn: conn, site: site} do stub_fetch_body(200, "") stub_installation(200, plausible_installed(false)) @@ -176,9 +196,9 @@ defmodule PlausibleWeb.Live.VerificationTest do {lv, html} end - defp get_lv_modal(conn, site) do + defp get_lv_modal(conn, site, query_string \\ "") do conn = conn |> no_slowdown() |> assign(:live_module, PlausibleWeb.Live.Verification) - {:ok, lv, html} = live(no_slowdown(conn), "/#{site.domain}/settings/general") + {:ok, lv, html} = live(no_slowdown(conn), "/#{site.domain}/settings/general#{query_string}") {lv, html} end