Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Move tracking options into general site settings (#6574)
Sanne de Vries754676a689cd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 58aef1482b..06ba4676f7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.- Redesigned authentication pages (register, sign in, 2FA, password reset, account activation)- Removed limitation that blocked users without owned sites from starting a subscription- Redesigned onboarding pages (add site, installation)+- Moved tracking options (outbound links, file downloads, form submissions) from the installation page to the general site settings, where they can be toggled without going through the installation flow- Replaced HCaptcha with Friendly Captcha### Fixeddiff --git a/assets/css/app.css b/assets/css/app.cssindex de89cd2127..c80f0cdb2d 100644--- a/assets/css/app.css+++ b/assets/css/app.css@@ -116,8 +116,23 @@}.btn-theme-icon {- @apply border border-transparent text-gray-400 dark:text-gray-400- hover:text-gray-900 dark:hover:text-gray-100;+ @apply border border-transparent text-gray-500 dark:text-gray-400+ hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100+ dark:hover:bg-gray-800 hover:border-gray-100 dark:hover:border-gray-800+ disabled:text-gray-400 disabled:dark:text-gray-600+ disabled:hover:bg-transparent disabled:hover:border-transparent;+ }++ .btn-theme-icon.btn-xs {+ @apply px-1;+ }++ .btn-theme-icon.btn-sm {+ @apply px-2;+ }++ .btn-theme-icon.btn-md {+ @apply px-2.5;}}diff --git a/lib/plausible_web.ex b/lib/plausible_web.exindex 67ba7b1565..6dbfb8cfff 100644--- a/lib/plausible_web.ex+++ b/lib/plausible_web.ex@@ -23,6 +23,7 @@ defmodule PlausibleWeb doalias Phoenix.LiveView.JSimport PlausibleWeb.Components.Generic+ import PlausibleWeb.Components.Settingsimport PlausibleWeb.Live.Components.Formendend@@ -31,6 +32,7 @@ defmodule PlausibleWeb doquote douse Phoenix.LiveComponent, global_prefixes: ~w(x-)import PlausibleWeb.Components.Generic+ import PlausibleWeb.Components.Settingsimport PlausibleWeb.Live.Components.Formalias Phoenix.LiveView.JSalias PlausibleWeb.Router.Helpers, as: Routes@@ -41,6 +43,7 @@ defmodule PlausibleWeb doquote douse Phoenix.Component, global_prefixes: ~w(x-)import PlausibleWeb.Components.Generic+ import PlausibleWeb.Components.Settingsimport PlausibleWeb.Live.Components.Formalias Phoenix.LiveView.JSalias PlausibleWeb.Router.Helpers, as: Routes@@ -68,6 +71,7 @@ defmodule PlausibleWeb douse Phoenix.Component, global_prefixes: ~w(x-)import PlausibleWeb.Components.Generic+ import PlausibleWeb.Components.Settingsimport PlausibleWeb.Live.Components.Formalias PlausibleWeb.Router.Helpers, as: Routesend@@ -85,6 +89,7 @@ defmodule PlausibleWeb douse Phoenix.Componentimport PlausibleWeb.Components.Generic+ import PlausibleWeb.Components.Settingsimport PlausibleWeb.Live.Components.Formalias PlausibleWeb.Router.Helpers, as: Routesenddiff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.exindex 120dc71ec5..d0e0e786a9 100644--- a/lib/plausible_web/components/generic.ex+++ b/lib/plausible_web/components/generic.ex@@ -194,9 +194,9 @@ defmodule PlausibleWeb.Components.Generic dohref={"https://plausible.io/docs/#{@slug}"}rel="noopener noreferrer"target="_blank"- class="inline-block"+ class="flex">- <Heroicons.information_circle class="text-gray-400 dark:text-indigo-500 size-5 hover:text-indigo-500 dark:hover:text-indigo-400 transition-colors duration-150" />+ <Heroicons.information_circle class="text-gray-400 dark:text-indigo-500 size-4.5 hover:text-indigo-500 dark:hover:text-indigo-400 transition-colors duration-150" /></a></.tooltip></div>@@ -550,7 +550,11 @@ defmodule PlausibleWeb.Components.Generic do~H"""<buttonid={"#{@id}-#{@id_suffix}"}- class={["h-6", if(@disabled, do: "cursor-not-allowed", else: "cursor-pointer")]}+ class={[+ "h-6",+ if(@disabled, do: "cursor-not-allowed", else: "cursor-pointer"),+ if(@server_mode?, do: "phx-click-loading:cursor-default phx-click-loading:opacity-60")+ ]}aria-labelledby={@id}role="switch"type="button"@@ -642,74 +646,10 @@ defmodule PlausibleWeb.Components.Generic do"""end- def settings_tiles(assigns) do- ~H"""- <div class="text-gray-900 leading-5 dark:text-gray-100">- {render_slot(@inner_block)}- </div>- """- end-- attr :docs, :string, default: nil- slot :inner_block, required: true- slot :title, required: true- slot :subtitle, required: false- attr :feature_mod, :atom, default: nil- attr :feature_toggle?, :boolean, default: false- attr :current_team, :any, default: nil- attr :current_user, :any, default: nil- attr :site, :any, default: nil- attr :conn, :any, default: nil- attr :show_content?, :boolean, default: true-- def tile(assigns) do- ~H"""- <div data-test-id="settings-tile" class="shadow-sm bg-white dark:bg-gray-900 rounded-md mb-6">- <header class="relative py-4 px-6">- <.title>- {render_slot(@title)}-- <.docs_info :if={@docs} slug={@docs} class="absolute top-4 right-4 z-1" />- </.title>- <div :if={@subtitle != []} class="text-sm mt-px text-gray-500 dark:text-gray-400 leading-5">- {render_slot(@subtitle)}- </div>-- <.live_component- :if={@feature_toggle?}- module={PlausibleWeb.Components.Site.Feature.ToggleLive}- id={"feature-toggle-#{@site.id}-#{@feature_mod}"}- site={@site}- feature_mod={@feature_mod}- current_user={@current_user}- />- </header>- <div class={["border-b dark:border-gray-700 mx-6", if(not @show_content?, do: "hidden")]}></div>- <div class={["relative", if(not @show_content?, do: "hidden")]}>- <%= if @feature_mod do %>- <PlausibleWeb.Components.Billing.feature_gate- locked?={@feature_mod.check_availability(@current_team) != :ok}- current_user={@current_user}- current_team={@current_team}- site={@site}- >- <div class="p-4 sm:p-6">- {render_slot(@inner_block)}- </div>- </PlausibleWeb.Components.Billing.feature_gate>- <% else %>- <div class="p-4 sm:p-6">- {render_slot(@inner_block)}- </div>- <% end %>- </div>- </div>- """- end-attr(:sticky?, :boolean, default: true)attr(:enabled?, :boolean, default: true)attr(:centered?, :boolean, default: false)+ attr(:interactive?, :boolean, default: true)attr(:testid, :string, default: nil)slot(:inner_block, required: true)slot(:tooltip_content, required: true)@@ -727,7 +667,8 @@ defmodule PlausibleWeb.Components.Generic do"-translate-y-full","z-[1000]","sm:max-w-64",- "w-max"+ "w-max",+ if(!assigns.interactive?, do: "pointer-events-none")]tooltip_position_classes =@@ -750,7 +691,7 @@ defmodule PlausibleWeb.Components.Generic dox-data={@wrapper_data}x-on:mouseenter="hovered = true"x-on:mouseleave="hovered = false"- class={["w-max relative z-[1000]"]}+ class="w-max relative"><divx-cloakdiff --git a/lib/plausible_web/components/icons.ex b/lib/plausible_web/components/icons.exindex ef2c90f712..551b7855ec 100644--- a/lib/plausible_web/components/icons.ex+++ b/lib/plausible_web/components/icons.ex@@ -49,15 +49,14 @@ defmodule PlausibleWeb.Components.Icons dodef tag_icon(assigns) do~H"""- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class={@class}>- <circle fill="currentColor" cx="7.25" cy="7.25" r="1.25" />+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={@class}>+ <path fill="currentColor" d="M8.7 10.2a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3" /><path- fill="none"stroke="currentColor"stroke-linecap="round"stroke-linejoin="round"stroke-width="1.5"- d="M4 3h5.172a2 2 0 0 1 1.414.586l5.536 5.536a3 3 0 0 1 0 4.243l-2.757 2.757a3 3 0 0 1-4.243 0l-5.536-5.536A2 2 0 0 1 3 9.172V4a1 1 0 0 1 1-1Z"+ d="M4.8 3.602h6.206a2.4 2.4 0 0 1 1.697.703l6.643 6.643a3.597 3.597 0 0 1 0 5.092l-3.308 3.308a3.6 3.6 0 0 1-5.092 0l-6.643-6.643a2.4 2.4 0 0 1-.703-1.697V4.802a1.2 1.2 0 0 1 1.2-1.2"/></svg>"""@@ -174,6 +173,68 @@ defmodule PlausibleWeb.Components.Icons doattr :class, :any, default: []+ def pencil_icon(assigns) do+ ~H"""+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={@class}>+ <path+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="m14.063 5.897 4.041 4.041M3.667 20.334s4.799-.757 6.061-2.02l9.77-9.77a2.857 2.857 0 0 0-4.04-4.04l-9.77 9.77c-1.262 1.263-2.02 6.061-2.02 6.061z"+ />+ </svg>+ """+ end++ attr :class, :any, default: []++ def button_click_icon(assigns) do+ ~H"""+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={@class}>+ <path+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="M21.666 11.178V7.667A2.667 2.667 0 0 0 19 5H5a2.667 2.667 0 0 0-2.667 2.667v4.666A2.667 2.667 0 0 0 5 15h4.197"+ />+ <path+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="m13.245 12.359 9.139 3.339a.43.43 0 0 1-.016.814l-4.183 1.339-1.339 4.183a.43.43 0 0 1-.814.016l-3.339-9.139a.43.43 0 0 1 .552-.552"+ />+ </svg>+ """+ end++ attr :class, :any, default: []++ def error_page_icon(assigns) do+ ~H"""+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={@class}>+ <path+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="M5.519 10.947c-2.482 2.041-3.839 3.923-3.296 4.864.829 1.435 5.765.135 11.026-2.902s8.855-6.663 8.027-8.098c-.543-.94-2.852-.707-5.86.422"+ />+ <path+ stroke="currentColor"+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="M8.25 4.25a6 6 0 0 1 8.196 2.196l-.215.243a18 18 0 0 1-9.86 5.692l-.317.065A6 6 0 0 1 8.25 4.25M18.75 21.75l-3-5M22.75 14.25l-2.5-1M10.25 19.25v3"+ />+ </svg>+ """+ end++ attr :class, :any, default: []+def envelope_icon(assigns) do~H"""<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={@class}>diff --git a/lib/plausible_web/components/settings.ex b/lib/plausible_web/components/settings.exnew file mode 100644index 0000000000..2528f52314--- /dev/null+++ b/lib/plausible_web/components/settings.ex@@ -0,0 +1,179 @@+defmodule PlausibleWeb.Components.Settings do+ @moduledoc """+ Shared layout components for settings pages.+ """+ use Phoenix.Component, global_prefixes: ~w(x-)++ import PlausibleWeb.Components.Generic++ alias PlausibleWeb.Live.Components.Form++ def settings_tiles(assigns) do+ ~H"""+ <div class="text-gray-900 leading-5 dark:text-gray-100">+ {render_slot(@inner_block)}+ </div>+ """+ end++ attr :docs, :string, default: nil+ slot :inner_block, required: true+ slot :title, required: true+ slot :subtitle, required: false+ attr :feature_mod, :atom, default: nil+ attr :feature_toggle?, :boolean, default: false+ attr :current_team, :any, default: nil+ attr :current_user, :any, default: nil+ attr :site, :any, default: nil+ attr :conn, :any, default: nil+ attr :show_content?, :boolean, default: true++ def tile(assigns) do+ ~H"""+ <div data-test-id="settings-tile" class="shadow-sm bg-white dark:bg-gray-900 rounded-md mb-6">+ <header class="relative py-4 px-6">+ <.title>+ {render_slot(@title)}++ <.docs_info :if={@docs} slug={@docs} class="absolute top-4 right-4 z-1" />+ </.title>+ <div :if={@subtitle != []} class="text-sm mt-px text-gray-500 dark:text-gray-400 leading-5">+ {render_slot(@subtitle)}+ </div>++ <.live_component+ :if={@feature_toggle?}+ module={PlausibleWeb.Components.Site.Feature.ToggleLive}+ id={"feature-toggle-#{@site.id}-#{@feature_mod}"}+ site={@site}+ feature_mod={@feature_mod}+ current_user={@current_user}+ />+ </header>+ <div class={["border-b dark:border-gray-700 mx-6", if(not @show_content?, do: "hidden")]}></div>+ <div class={["relative", if(not @show_content?, do: "hidden")]}>+ <%= if @feature_mod do %>+ <PlausibleWeb.Components.Billing.feature_gate+ locked?={@feature_mod.check_availability(@current_team) != :ok}+ current_user={@current_user}+ current_team={@current_team}+ site={@site}+ >+ <div class="p-4 sm:p-6">+ {render_slot(@inner_block)}+ </div>+ </PlausibleWeb.Components.Billing.feature_gate>+ <% else %>+ <div class="p-4 sm:p-6">+ {render_slot(@inner_block)}+ </div>+ <% end %>+ </div>+ </div>+ """+ end++ slot :inner_block, required: true++ def settings_rows(assigns) do+ ~H"""+ <div class="flex flex-col gap-6">+ {render_slot(@inner_block)}+ </div>+ """+ end++ attr(:label, :string, default: nil)+ attr(:for, :string, default: nil)+ attr(:docs, :string, default: nil)+ attr(:tooltip, :string, default: nil)+ attr(:actions_class, :any, default: "gap-2.5")+ attr(:rest, :global)+ slot(:inner_block, required: true)++ def settings_row(assigns) do+ ~H"""+ <div+ class="flex flex-col items-stretch gap-3 sm:flex-row sm:items-center sm:gap-4 text-sm"+ {@rest}+ >+ <.settings_label+ :if={@label}+ label={@label}+ for={@for}+ docs={@docs}+ tooltip={@tooltip}+ />+ <div class={["flex items-center sm:ml-auto", @actions_class]}>+ {render_slot(@inner_block)}+ </div>+ </div>+ """+ end++ attr(:title, :string, required: true)+ attr(:docs, :string, default: nil)+ attr(:tooltip, :string, default: nil)+ attr(:expandable?, :boolean, default: false)+ slot(:inner_block, required: true)++ def settings_section(%{expandable?: true} = assigns) do+ ~H"""+ <section class="flex flex-col gap-6" x-data="{ open: false }">+ <button+ type="button"+ class="flex items-center justify-between gap-4"+ aria-expanded="false"+ x-bind:aria-expanded="open"+ x-on:click="open = !open"+ >+ <.settings_label label={@title} docs={@docs} tooltip={@tooltip} />+ <Heroicons.chevron_down+ mini+ class="size-4.5 text-gray-500 dark:text-gray-400 transition-transform"+ x-bind:class="open ? 'rotate-180' : ''"+ />+ </button>+ <div x-show="open" x-cloak class="flex flex-col gap-4">+ {render_slot(@inner_block)}+ </div>+ </section>+ """+ end++ def settings_section(assigns) do+ ~H"""+ <section class="flex flex-col gap-6">+ <.settings_label label={@title} docs={@docs} tooltip={@tooltip} />+ <div class="flex flex-col gap-4">+ {render_slot(@inner_block)}+ </div>+ </section>+ """+ end++ attr(:label, :string, required: true)+ attr(:for, :string, default: nil)+ attr(:docs, :string, default: nil)+ attr(:tooltip, :string, default: nil)++ def settings_label(assigns) do+ ~H"""+ <div class="flex items-center gap-1.5">+ <Form.label :if={@for} for={@for}>{@label}</Form.label>+ <span :if={!@for} class="text-sm font-medium dark:text-gray-100">{@label}</span>+ <.docs_info :if={@docs} slug={@docs} />+ <.tooltip :if={@tooltip} centered?={true}>+ <:tooltip_content>{@tooltip}</:tooltip_content>+ <Heroicons.information_circle class="size-4.5 text-gray-400 dark:text-gray-500" />+ </.tooltip>+ </div>+ """+ end++ def settings_divider(assigns) do+ ~H"""+ <hr class="border-gray-200 dark:border-gray-700" />+ """+ end+enddiff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex a2acddef51..1ee302d5e3 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -288,6 +288,7 @@ defmodule PlausibleWeb.SiteController do|> render("settings_general.html",site: site,changeset: changeset,+ connect_live_socket: true,layout: {PlausibleWeb.LayoutView, "site_settings.html"})enddiff --git a/lib/plausible_web/live/installation.ex b/lib/plausible_web/live/installation.exindex 91d9e9c3ef..f4ef6cf634 100644--- a/lib/plausible_web/live/installation.ex+++ b/lib/plausible_web/live/installation.ex@@ -81,14 +81,21 @@ defmodule PlausibleWeb.Live.Installation do)end+ {heading, subtitle} =+ if flow == Flows.review() do+ {"Review installation", "See how to install Plausible on your site."}+ else+ {"Add tracking to your site", "Install Plausible on #{site.domain} to start seeing data."}+ end+{:ok,assign(socket,site: site,flow: flow,return_to: params["return_to"],current_step: "Install Plausible",- heading: "Add tracking to your site",- subtitle: "Install Plausible on #{site.domain} to start seeing data."+ heading: heading,+ subtitle: subtitle)}end@@ -178,7 +185,6 @@ defmodule PlausibleWeb.Live.Installation do<Instructions.manual_instructions:if={@installation_type.result == "manual"}tracker_script_configuration_form={@tracker_script_configuration_form.result}- flow={@flow}/><Instructions.wordpress_instructionsdiff --git a/lib/plausible_web/live/installation/instructions.ex b/lib/plausible_web/live/installation/instructions.exindex 6ec59c7c9f..1a89319809 100644--- a/lib/plausible_web/live/installation/instructions.ex+++ b/lib/plausible_web/live/installation/instructions.ex@@ -3,10 +3,8 @@ defmodule PlausibleWeb.Live.Installation.Instructions doInstruction forms and components for the Installation module"""use PlausibleWeb, :component- alias PlausibleWeb.Flowsattr :tracker_script_configuration_form, :map, required: true- attr :flow, :string, required: truedef manual_instructions(assigns) do~H"""@@ -35,73 +33,6 @@ defmodule PlausibleWeb.Live.Installation.Instructions do</.styled_link></p></div>-- <div :if={@flow == Flows.review()}>- <label class="text-sm font-semibold text-gray-800 dark:text-gray-200">- Optional measurements- </label>- <.script_config_control- field={@tracker_script_configuration_form[:outbound_links]}- label="Outbound links"- tooltip="Automatically track clicks on external links. These count towards your billable pageviews."- learn_more="https://plausible.io/docs/outbound-link-click-tracking"- />- <.script_config_control- field={@tracker_script_configuration_form[:file_downloads]}- label="File downloads"- tooltip="Automatically track file downloads. These count towards your billable pageviews."- learn_more="https://plausible.io/docs/file-downloads-tracking"- />- <.script_config_control- field={@tracker_script_configuration_form[:form_submissions]}- label="Form submissions"- tooltip="Automatically track form submissions. These count towards your billable pageviews."- learn_more="https://plausible.io/docs/form-submissions-tracking"- />-- <.disclosure>- <.disclosure_button class="mt-10 flex items-center group">- <label class="text-sm font-semibold text-gray-800 dark:text-gray-200 cursor-pointer">- Advanced options- </label>- <Heroicons.chevron_down mini class="size-4 ml-1 mt-0.5 group-data-[open=true]:rotate-180" />- </.disclosure_button>- <.disclosure_panel>- <ul class="list-disc list-inside mt-2 space-y-2">- <.advanced_option- variant="tagged-events"- label="Manual tagging"- tooltip="Tag site elements like buttons, links and forms to track user activity. These count towards your billable pageviews. Additional action required."- learn_more="https://plausible.io/docs/custom-event-goals"- />- <.advanced_option- variant="404"- label="404 error pages"- tooltip="Find 404 error pages on your site. These count towards your billable pageviews. Additional action required."- learn_more="https://plausible.io/docs/error-pages-tracking-404"- />- <.advanced_option- variant="hash"- label="Hashed page paths"- tooltip="Automatically track page paths that use a # in the URL."- learn_more="https://plausible.io/docs/hash-based-routing"- />- <.advanced_option- variant="pageview-props"- label="Custom properties"- tooltip="Attach custom properties (also known as custom dimensions) to pageviews or custom events to create custom metrics. Additional action required."- learn_more="https://plausible.io/docs/custom-props/introduction"- />- <.advanced_option- variant="revenue"- label="Ecommerce revenue"- tooltip="Assign monetary values to purchases and track revenue attribution. Additional action required."- learn_more="https://plausible.io/docs/ecommerce-revenue-tracking"- />- </ul>- </.disclosure_panel>- </.disclosure>- </div>"""end@@ -179,63 +110,6 @@ defmodule PlausibleWeb.Live.Installation.Instructions do"""end- attr :field, :any, required: true- attr :label, :string, required: true- attr :tooltip, :string, required: true- attr :learn_more, :string, required: true-- defp script_config_control(assigns) do- ~H"""- <div class="mt-2 p-1 text-sm">- <div class="flex items-center">- <.input mt?={false} field={@field} label={@label} type="checkbox" />- <div class="ml-2 collapse md:visible">- <.tooltip sticky?={false}>- <:tooltip_content>- {@tooltip}- <br />Click to learn more.- </:tooltip_content>- <a href={@learn_more} target="_blank" rel="noopener noreferrer">- <Heroicons.information_circle class="inline-block text-indigo-700 dark:text-gray-500 size-5 hover:stroke-2" />- </a>- </.tooltip>- </div>- <div class="ml-2 visible md:invisible">- <a href={@learn_more} target="_blank" rel="noopener noreferrer">- <Heroicons.information_circle class="inline-block text-indigo-700 dark:text-gray-500 size-5 hover:stroke-2" />- </a>- </div>- </div>- </div>- """- end-- defp advanced_option(assigns) do- ~H"""- <li class="p-1 text-sm">- <div class="inline-flex items-center">- <div>{@label}</div>- <div class="ml-2 collapse md:visible">- <.tooltip sticky?={false}>- <:tooltip_content>- {@tooltip}- <br />Click to learn more.- </:tooltip_content>- <a href={@learn_more} target="_blank" rel="noopener noreferrer">- <Heroicons.information_circle class="inline-block text-indigo-700 dark:text-gray-500 size-5 hover:stroke-2" />- </a>- </.tooltip>- </div>- <div class="ml-2 visible md:invisible">- <a href={@learn_more} target="_blank" rel="noopener noreferrer">- <Heroicons.information_circle class="inline-block text-indigo-700 dark:text-gray-500 size-5 hover:stroke-2" />- </a>- </div>- </div>- </li>- """- end-slot :step, required: truedefp steps_list(assigns) dodiff --git a/lib/plausible_web/live/tracking_settings.ex b/lib/plausible_web/live/tracking_settings.exnew file mode 100644index 0000000000..d6c4992464--- /dev/null+++ b/lib/plausible_web/live/tracking_settings.ex@@ -0,0 +1,223 @@+defmodule PlausibleWeb.Live.TrackingSettings do+ @moduledoc """+ LiveView for the tracking tile on the site general settings page. Shows the+ installation status, allows toggling the measurements that are tracked+ automatically, and lists the ones that require manual setup.+ """+ use PlausibleWeb, :live_view++ alias PlausibleWeb.Components.Icons++ @toggleable_fields %{+ "outbound_links" => "Outbound link tracking",+ "file_downloads" => "File download tracking",+ "form_submissions" => "Form submission tracking"+ }++ def mount(_params, %{"domain" => domain}, socket) do+ socket =+ socket+ |> assign_new(:site, fn %{current_user: current_user} ->+ Plausible.Sites.get_for_user!(current_user, domain,+ roles: [:owner, :admin, :editor, :super_admin]+ )+ end)++ {:ok,+ socket+ |> assign(+ tracker_script_configuration:+ PlausibleWeb.Tracker.get_or_create_tracker_script_configuration!(socket.assigns.site)+ )+ |> assign(:installation_status, installation_status(socket.assigns.site))}+ end++ def render(assigns) do+ ~H"""+ <div id="tracking-settings-main">+ <.flash_messages flash={@flash} />++ <.tile docs={if ce?(), do: "plausible-script"}>+ <:title>Tracking</:title>+ <:subtitle>Manage how Plausible collects data for this site.</:subtitle>++ <.settings_rows>+ <.settings_row+ label={+ if @installation_status, do: "Site installation", else: "Installation instructions"+ }+ docs="plausible-script"+ >+ <.status_indicator :if={@installation_status} status={@installation_status} />+ <.styled_link+ href={review_installation_path(@site)}+ aria-label="View setup"+ class="text-sm"+ >+ Review+ </.styled_link>+ </.settings_row>++ <.settings_divider />++ <.settings_section+ title="Default tracking"+ tooltip="Automatically track these events for your site."+ >+ <.measurement label="Outbound links">+ <:icon><Heroicons.link class="size-4.5" /></:icon>+ <.toggle_switch+ id="outbound_links"+ checked={@tracker_script_configuration.outbound_links}+ phx-click="toggle"+ phx-value-field="outbound_links"+ />+ </.measurement>+ <.measurement label="File downloads">+ <:icon><Heroicons.arrow_down_tray class="size-4.5" /></:icon>+ <.toggle_switch+ id="file_downloads"+ checked={@tracker_script_configuration.file_downloads}+ phx-click="toggle"+ phx-value-field="file_downloads"+ />+ </.measurement>+ <.measurement label="Form submissions">+ <:icon><Icons.button_click_icon class="size-4.5" /></:icon>+ <.toggle_switch+ id="form_submissions"+ checked={@tracker_script_configuration.form_submissions}+ phx-click="toggle"+ phx-value-field="form_submissions"+ />+ </.measurement>+ </.settings_section>++ <.settings_divider />++ <.settings_section+ title="Additional tracking"+ tooltip="These tracking options require manual setup."+ expandable?={true}+ >+ <.measurement label="Custom event tracking">+ <:icon><Heroicons.check_circle class="size-4.5" /></:icon>+ <.learn_more href="https://plausible.io/docs/custom-event-goals" />+ </.measurement>+ <.measurement label="404 error pages">+ <:icon><Icons.error_page_icon class="size-4.5" /></:icon>+ <.learn_more href="https://plausible.io/docs/error-pages-tracking-404" />+ </.measurement>+ <.measurement label="Hashed page paths">+ <:icon><Heroicons.hashtag class="size-4.5" /></:icon>+ <.learn_more href="https://plausible.io/docs/hash-based-routing" />+ </.measurement>+ <.measurement label="Custom properties">+ <:icon><Icons.tag_icon class="size-4.5" /></:icon>+ <.learn_more href="https://plausible.io/docs/custom-props/introduction" />+ </.measurement>+ <.measurement label="Ecommerce revenue">+ <:icon><Heroicons.shopping_cart class="size-4.5" /></:icon>+ <.learn_more href="https://plausible.io/docs/ecommerce-revenue-tracking" />+ </.measurement>+ </.settings_section>+ </.settings_rows>+ </.tile>+ </div>+ """+ end++ def handle_event("toggle", %{"field" => field}, socket)+ when is_map_key(@toggleable_fields, field) do+ configuration = socket.assigns.tracker_script_configuration+ enabled? = not Map.fetch!(configuration, String.to_existing_atom(field))++ updated_configuration =+ PlausibleWeb.Tracker.update_script_configuration!(+ socket.assigns.site,+ %{field => enabled?},+ :installation+ )++ message =+ "#{Map.fetch!(@toggleable_fields, field)} #{if enabled?, do: "enabled", else: "disabled"}"++ {:noreply,+ socket+ |> assign(tracker_script_configuration: updated_configuration)+ |> put_live_flash(:success, message)}+ end++ defp status_indicator(%{status: :completed} = assigns) do+ ~H"""+ <div class="flex items-center gap-1.5 text-gray-800 dark:text-gray-200">+ <span class="size-2 rounded-full bg-green-500"></span> Completed+ </div>+ """+ end++ defp status_indicator(%{status: :pending} = assigns) do+ ~H"""+ <div class="flex items-center gap-1.5 text-gray-800 dark:text-gray-200">+ <span class="size-2 rounded-full bg-yellow-500"></span> Pending+ </div>+ """+ end++ attr :label, :string, required: true+ slot :icon, required: true+ slot :inner_block, required: true++ defp measurement(assigns) do+ ~H"""+ <div class="flex items-center justify-between gap-4 text-sm">+ <div class="flex items-center gap-2 text-gray-800 dark:text-gray-200">+ {render_slot(@icon)}+ {@label}+ </div>+ {render_slot(@inner_block)}+ </div>+ """+ end++ attr :href, :string, required: true++ defp learn_more(assigns) do+ ~H"""+ <.tooltip centered?={true} interactive?={false}>+ <:tooltip_content>Learn more</:tooltip_content>+ <.button_link+ theme="icon"+ size="xs"+ mt?={false}+ href={@href}+ target="_blank"+ rel="noopener noreferrer"+ aria-label="Learn more"+ >+ <Icons.external_link_icon class="size-4 [&_path]:stroke-2" />+ </.button_link>+ </.tooltip>+ """+ end++ defp review_installation_path(site) do+ Routes.site_path(PlausibleWeb.Endpoint, :installation, site.domain,+ flow: PlausibleWeb.Flows.review()+ )+ end++ on_ee do+ @completed_onboarding_statuses [:verification_succeeded, :first_pageview, :completed]++ defp installation_status(site) do+ if site.onboarding_status in @completed_onboarding_statuses do+ :completed+ else+ :pending+ end+ end+ else+ defp installation_status(_), do: nil+ end+enddiff --git a/lib/plausible_web/templates/site/settings_general.html.heex b/lib/plausible_web/templates/site/settings_general.html.heexindex 61fbc55fac..5bbd8c3750 100644--- a/lib/plausible_web/templates/site/settings_general.html.heex+++ b/lib/plausible_web/templates/site/settings_general.html.heex@@ -1,47 +1,58 @@<.settings_tiles>- <.tile :if={Plausible.Sites.regular?(@site)} docs="change-domain-name">- <:title>- Site domain- </:title>- <:subtitle>- Moving your site to a different domain? We got you!- </:subtitle>- <.input name="domain" label="Domain" value={@site.domain} disabled width="w-1/2" mt?={false} />+ <.tile>+ <:title>Site details</:title>+ <:subtitle>Manage your site configuration</:subtitle>- <.button_link href={Routes.site_path(@conn, :change_domain, @site.domain)}>- Change domain- </.button_link>- </.tile>+ <.settings_rows>+ <%= if Plausible.Sites.regular?(@site) do %>+ <.settings_row label="Site domain" docs="change-domain-name">+ <span class="text-gray-800 dark:text-gray-200">{@site.domain}</span>+ <.styled_link+ href={Routes.site_path(@conn, :change_domain, @site.domain)}+ aria-label="Change domain"+ class="text-sm"+ >+ Change+ </.styled_link>+ </.settings_row>- <.tile docs="general">- <:title>Site timezone</:title>- <:subtitle>Update your reporting timezone.</:subtitle>- <.form :let={f} for={@changeset} action={"/#{URI.encode_www_form(@site.domain)}/settings"}>- <.input- field={f[:timezone]}- label="Reporting timezone"- type="select"- options={Plausible.Timezones.options()}- width="w-1/2"- mt?={false}- />- <.button type="submit">- Save timezone- </.button>- </.form>- </.tile>- <.tile :if={Plausible.Sites.regular?(@site)} docs="plausible-script">- <:title>Site installation</:title>- <:subtitle>- Control what data is collected and verify your installation.- </:subtitle>- <.button_link- href={- Routes.site_path(@conn, :installation, @site.domain, flow: PlausibleWeb.Flows.review())- }- mt?={false}- >- Review installation- </.button_link>+ <.settings_divider />+ <% end %>++ <.form :let={f} for={@changeset} action={"/#{URI.encode_www_form(@site.domain)}/settings"}>+ <.settings_row+ label="Reporting timezone"+ for={f[:timezone].id}+ docs="general"+ actions_class="gap-3"+ x-data={"{ changed: false, saved: '#{@site.timezone}' }"}+ x-on:change="changed = $event.target.value !== saved"+ >+ <div class="min-w-0">+ <.input+ field={f[:timezone]}+ type="select"+ options={Plausible.Timezones.options()}+ width="w-full max-w-72"+ mt?={false}+ />+ </div>+ <.button+ theme="secondary"+ type="submit"+ class="shrink-0"+ mt?={false}+ disabled+ x-bind:disabled="!changed"+ >+ Save+ </.button>+ </.settings_row>+ </.form>+ </.settings_rows></.tile>++ <%= if Plausible.Sites.regular?(@site) do %>+ {live_render(@conn, PlausibleWeb.Live.TrackingSettings, session: %{"domain" => @site.domain})}+ <% end %></.settings_tiles>diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 466cfede5e..3dbb58ce58 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -675,13 +675,18 @@ defmodule PlausibleWeb.SiteControllerTest doresp = html_response(conn, 200)assert resp =~ "Settings for #{site.domain}"+ assert resp =~ "Site details"assert resp =~ "Site domain"- assert resp =~ "Change domain"assert resp =~ Routes.site_path(conn, :change_domain, site.domain)- assert resp =~ "Site timezone"+ assert resp =~ "Reporting timezone"- assert resp =~ "Site installation"+ assert resp =~ "Tracking"++ assert resp =~+ Routes.site_path(conn, :installation, site.domain,+ flow: PlausibleWeb.Flows.review()+ )endon_ee do@@ -693,7 +698,8 @@ defmodule PlausibleWeb.SiteControllerTest doresp = html_response(conn, 200)assert [tile_element] = find(resp, ~s|div[data-test-id="settings-tile"]|) |> Enum.into([])- assert text(tile_element) =~ "Site timezone"+ assert text(tile_element) =~ "Reporting timezone"+ refute text(tile_element) =~ "Site domain"endenddiff --git a/test/plausible_web/live/installation_test.exs b/test/plausible_web/live/installation_test.exsindex d443867837..efb32aef27 100644--- a/test/plausible_web/live/installation_test.exs+++ b/test/plausible_web/live/installation_test.exs@@ -180,41 +180,7 @@ defmodule PlausibleWeb.Live.InstallationTest doassert html =~ "async"end- test "manual installation shows optional measurements", %{conn: conn, site: site} do- on_ee do- stub_dns()- stub_detection_manual()- end-- {lv, _html} = get_lv(conn, site, "?type=manual&flow=review")-- html = render_async(lv, 500)- assert html =~ htmlize_quotes(@submit_button_text)- assert html =~ "Optional measurements"- assert html =~ "Outbound links"- assert html =~ "File downloads"- assert html =~ "Form submissions"- end-- test "manual installation shows advanced options in disclosure", %{conn: conn, site: site} do- on_ee do- stub_dns()- stub_detection_manual()- end-- {lv, _html} = get_lv(conn, site, "?type=manual&flow=review")-- html = render_async(lv, 500)- assert html =~ htmlize_quotes(@submit_button_text)- assert html =~ "Advanced options"- assert html =~ "Manual tagging"- assert html =~ "404 error pages"- assert html =~ "Hashed page paths"- assert html =~ "Custom properties"- assert html =~ "Ecommerce revenue"- end-- test "toggling optional measurements updates tracker configuration", %{+ test "tracker configuration is created with the default measurements enabled", %{conn: conn,site: site} do@@ -232,22 +198,7 @@ defmodule PlausibleWeb.Live.InstallationTest doassert config.outbound_links == trueassert config.file_downloads == trueassert config.form_submissions == true-- lv- |> element("form[phx-submit='submit']")- |> render_submit(%{- "tracker_script_configuration" => %{- "installation_type" => "manual",- "outbound_links" => "false",- "file_downloads" => "true",- "form_submissions" => "true"- }- })-- updated_config = TrackerScriptConfiguration |> Plausible.Repo.get_by!(site_id: site.id)- assert updated_config.outbound_links == false- assert updated_config.file_downloads == true- assert updated_config.form_submissions == true+ assert config.track_404_pages == trueendon_ee do@@ -269,10 +220,7 @@ defmodule PlausibleWeb.Live.InstallationTest do|> element("form[phx-submit='submit']")|> render_submit(%{"tracker_script_configuration" => %{- "installation_type" => unquote(type),- "outbound_links" => "true",- "file_downloads" => "true",- "form_submissions" => "true"+ "installation_type" => unquote(type)}})@@ -298,44 +246,13 @@ defmodule PlausibleWeb.Live.InstallationTest do|> element("form[phx-submit='submit']")|> render_submit(%{"tracker_script_configuration" => %{- "installation_type" => "manual",- "outbound_links" => "true",- "file_downloads" => "true",- "form_submissions" => "true"+ "installation_type" => "manual"}})assert_redirect(lv, Routes.stats_path(conn, :stats, site.domain))end- test "404 goal gets created regardless of user options", %{conn: conn, site: site} do- on_ee do- stub_dns()- stub_detection_manual()- end-- {lv, _html} = get_lv(conn, site, "?type=manual")-- html = render_async(lv, 500)- assert html =~ htmlize_quotes(@submit_button_text)-- # Test with all options disabled- lv- |> element("form[phx-submit='submit']")- |> render_submit(%{- "tracker_script_configuration" => %{- "installation_type" => "manual",- "outbound_links" => "false",- "file_downloads" => "false",- "form_submissions" => "false"- }- })-- # 404 goal should still be created- goals = Plausible.Goals.for_site(site)- assert Enum.any?(goals, &(&1.event_name == "404"))- end-test "submitting form with review flow redirects to the dashboard with the flow param preserved",%{conn: conn,@@ -355,10 +272,7 @@ defmodule PlausibleWeb.Live.InstallationTest do|> element("form[phx-submit='submit']")|> render_submit(%{"tracker_script_configuration" => %{- "installation_type" => "manual",- "outbound_links" => "true",- "file_downloads" => "true",- "form_submissions" => "true"+ "installation_type" => "manual"}})diff --git a/test/plausible_web/live/tracking_settings_test.exs b/test/plausible_web/live/tracking_settings_test.exsnew file mode 100644index 0000000000..7531c38bdb--- /dev/null+++ b/test/plausible_web/live/tracking_settings_test.exs@@ -0,0 +1,144 @@+defmodule PlausibleWeb.Live.TrackingSettingsTest do+ use PlausibleWeb.ConnCase, async: true++ import Phoenix.LiveViewTest++ alias Plausible.Site.TrackerScriptConfiguration++ setup [:create_user, :log_in, :create_site]++ describe "TrackingSettings LiveView" do+ test "renders the default measurements with their persisted state", %{+ conn: conn,+ site: site+ } do+ PlausibleWeb.Tracker.get_or_create_tracker_script_configuration!(site, %{+ outbound_links: true,+ file_downloads: false,+ form_submissions: true+ })++ html = conn |> get_liveview(site) |> render()++ assert html =~ "Default tracking"+ assert toggle_state(html, "outbound_links") == "true"+ assert toggle_state(html, "file_downloads") == "false"+ assert toggle_state(html, "form_submissions") == "true"+ end++ test "toggling a measurement persists it and shows a success message", %{+ conn: conn,+ site: site+ } do+ PlausibleWeb.Tracker.get_or_create_tracker_script_configuration!(site, %{+ outbound_links: true+ })++ lv = get_liveview(conn, site)++ html = toggle(lv, "outbound_links")++ assert html =~ "Outbound link tracking disabled"+ assert toggle_state(html, "outbound_links") == "false"+ refute configuration(site).outbound_links++ html = toggle(lv, "outbound_links")++ assert html =~ "Outbound link tracking enabled"+ assert toggle_state(html, "outbound_links") == "true"+ assert configuration(site).outbound_links+ end++ test "toggling a measurement syncs the corresponding goal", %{conn: conn, site: site} do+ PlausibleWeb.Tracker.get_or_create_tracker_script_configuration!(site, %{+ file_downloads: false+ })++ lv = get_liveview(conn, site)++ assert toggle(lv, "file_downloads") =~ "File download tracking enabled"++ assert Enum.any?(Plausible.Goals.for_site(site), &(&1.event_name == "File Download"))+ end++ test "lists the measurements that require manual setup", %{conn: conn, site: site} do+ html = conn |> get_liveview(site) |> render()++ assert html =~ "Additional tracking"+ assert html =~ "Custom event tracking"+ assert html =~ "404 error pages"+ assert html =~ "Hashed page paths"+ assert html =~ "Custom properties"+ assert html =~ "Ecommerce revenue"+ assert html =~ "https://plausible.io/docs/ecommerce-revenue-tracking"+ end++ test "links to the installation review flow", %{conn: conn, site: site} do+ html = conn |> get_liveview(site) |> render()++ assert html =~+ Routes.site_path(PlausibleWeb.Endpoint, :installation, site.domain,+ flow: PlausibleWeb.Flows.review()+ )+ end++ @tag :ee_only+ test "shows completed installation once verified", %{conn: conn, site: site} do+ site = set_onboarding_status(site, :completed)++ html = conn |> get_liveview(site) |> render()++ assert html =~ "Site installation"+ assert html =~ "Completed"+ end++ @tag :ee_only+ test "shows pending installation when never verified", %{conn: conn, site: site} do+ site = set_onboarding_status(site, :new_site)++ html = conn |> get_liveview(site) |> render()++ assert html =~ "Site installation"+ assert html =~ "Pending"+ end++ @tag :ce_build_only+ test "does not show installation status on CE", %{conn: conn, site: site} do+ site = set_onboarding_status(site, :new_site)++ html = conn |> get_liveview(site) |> render()++ assert html =~ "Installation instructions"+ refute html =~ "Site installation"+ assert html =~ "https://plausible.io/docs/plausible-script"+ assert html =~ "Review"+ end+ end++ defp get_liveview(conn, site) do+ {:ok, lv, _html} =+ live_isolated(conn, PlausibleWeb.Live.TrackingSettings, session: %{"domain" => site.domain})++ lv+ end++ defp toggle(lv, field) do+ lv+ |> element(~s|button[phx-value-field="#{field}"]|)+ |> render_click()+ end++ defp toggle_state(html, field) do+ text_of_attr(html, ~s|button[phx-value-field="#{field}"]|, "aria-checked")+ end++ defp configuration(site) do+ Plausible.Repo.get_by!(TrackerScriptConfiguration, site_id: site.id)+ end++ defp set_onboarding_status(site, status) do+ site+ |> Ecto.Changeset.change(onboarding_status: status)+ |> Plausible.Repo.update!()+ end+end