defmodule PlausibleWeb.Live.Components.Verification do @moduledoc """ This component is responsible for rendering the verification progress and diagnostics. """ use Phoenix.LiveComponent use Plausible alias PlausibleWeb.Router.Helpers, as: Routes alias Plausible.InstallationSupport.{State, Result} import PlausibleWeb.Components.Generic attr(:domain, :string, required: true) attr(:message, :string, default: "We're visiting your site to ensure that everything is working" ) attr(:super_admin?, :boolean, default: false) attr(:finished?, :boolean, default: false) attr(:success?, :boolean, default: false) attr(:verification_state, State, default: nil) attr(:interpretation, Result, default: nil) attr(:attempts, :integer, default: 0) attr(:flow, :string, default: "") attr(:installation_type, :string, default: nil) attr(:awaiting_first_pageview?, :boolean, default: false) def render(assigns) do ~H"""
<.render_progress :if={not @finished?} message={@message} /> <.render_success :if={@finished? and @success?} awaiting_first_pageview?={@awaiting_first_pageview?} domain={@domain} /> <.render_failed :if={@finished? and not @success?} interpretation={@interpretation} attempts={@attempts} domain={@domain} flow={@flow} installation_type={@installation_type} /> <.render_super_admin_diagnostics :if={not is_nil(@verification_state) && @super_admin? && @finished?} verification_state={@verification_state} />
""" end defp render_progress(assigns) do ~H""" <.focus_box>
<.title>Verifying your installation

{@message}

""" end defp render_success(assigns) do ~H""" <.focus_box>
<.title>Success!

Your installation is working and visitors are being counted accurately. Awaiting your first pageview...

<.button_link href={"/#{URI.encode_www_form(@domain)}?skip_to_dashboard=true"} class="w-full font-bold mb-4" > Go to the dashboard """ end defp render_failed(assigns) do ~H""" <.focus_box>
<.title>{List.first(@interpretation.errors)}

{List.first(@interpretation.recommendations).text}.  <.styled_link href={List.first(@interpretation.recommendations).url} new_tab={true}> Learn more

<.button_link mt?={false} href="#" phx-click="retry" class="w-full"> Verify installation again
<:footer> <.focus_list> <:item :if={ @interpretation && is_map(@interpretation.data) && @interpretation.data[:offer_custom_url_input] }> Is your website located at a different URL? <.styled_link href={ Routes.site_path(PlausibleWeb.Endpoint, :verification, @domain, flow: @flow, installation_type: @installation_type, custom_url: true ) }> Click here <:item :if={ee?() and @attempts >= 3}> Need further help with your installation? <.styled_link href="https://plausible.io/contact"> Contact us <:item> Need to see installation instructions again? <.styled_link href={ Routes.site_path(PlausibleWeb.Endpoint, :installation, @domain, flow: @flow, installation_type: @installation_type ) }> Click here <:item> Run verification later and go to site settings? <.styled_link href={"/#{URI.encode_www_form(@domain)}/settings/general"}> Click here """ end defp render_super_admin_diagnostics(assigns) do ~H""" <.focus_box>

As a super-admin, you're eligible to see diagnostics details. Click to expand.

<.focus_list> <:item :for={{diag, value} <- Map.from_struct(@verification_state.diagnostics)}> {Phoenix.Naming.humanize(diag)}: {to_string_value(value)}
""" end defp to_string_value(value) when is_binary(value), do: value defp to_string_value(value), do: inspect(value) end