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
Dogfooding improvements (#3290)
Uku Tahtbe1a679933f2
diff --git a/assets/js/app.js b/assets/js/app.jsindex a5762bd8ef..5d5c94f580 100644--- a/assets/js/app.js+++ b/assets/js/app.js@@ -36,12 +36,12 @@ if (triggers.length > 0) {})}-const registerForm = document.getElementById('register-form')+const registerForm = document.getElementById('register-via-invitation-form')if (registerForm) {registerForm.addEventListener('submit', function(e) {e.preventDefault();- setTimeout(submitForm, 1000);+ setTimeout(submitForm, 5000);var formSubmitted = false;function submitForm() {@@ -51,7 +51,7 @@ if (registerForm) {}}/* eslint-disable-next-line no-undef */- plausible('Signup', { callback: submitForm });+ plausible('Signup via invitation', {u: '/register/invitation/:invitation_id', callback: submitForm });})}diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.exindex 5d44be0f24..f0a757ff1a 100644--- a/lib/plausible_web/controllers/auth_controller.ex+++ b/lib/plausible_web/controllers/auth_controller.ex@@ -98,13 +98,13 @@ defmodule PlausibleWeb.AuthController dorender(conn, "register_from_invitation_form.html",changeset: changeset,invitation: invitation,- layout: {PlausibleWeb.LayoutView, "focus.html"},- skip_plausible_tracking: true+ dogfood_page_path: "/register/invitation/:invitation_id",+ layout: {PlausibleWeb.LayoutView, "focus.html"})elserender(conn, "invitation_expired.html",- layout: {PlausibleWeb.LayoutView, "focus.html"},- skip_plausible_tracking: true+ dogfood_page_path: "/register/invitation/:invitation_id",+ layout: {PlausibleWeb.LayoutView, "focus.html"})endend@@ -142,7 +142,7 @@ defmodule PlausibleWeb.AuthController doinvitation: invitation,changeset: changeset,layout: {PlausibleWeb.LayoutView, "focus.html"},- skip_plausible_tracking: true+ dogfood_page_path: "/register/invitation/:invitation_id")endelse@@ -151,7 +151,7 @@ defmodule PlausibleWeb.AuthController dochangeset: user,captcha_error: "Please complete the captcha to register",layout: {PlausibleWeb.LayoutView, "focus.html"},- skip_plausible_tracking: true+ dogfood_page_path: "/register/invitation/:invitation_id")endenddiff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 24c37ebbc7..7f077c24d9 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -179,11 +179,11 @@ defmodule PlausibleWeb.SiteController doendconn- |> assign(:skip_plausible_tracking, true)|> render("settings_general.html",site: site,imported_pageviews: imported_pageviews,changeset: Plausible.Site.changeset(site, %{}),+ dogfood_page_path: "/:dashboard/settings/general",layout: {PlausibleWeb.LayoutView, "site_settings.html"})end@@ -194,9 +194,9 @@ defmodule PlausibleWeb.SiteController do|> Repo.preload(memberships: :user, invitations: [], custom_domain: [])conn- |> assign(:skip_plausible_tracking, true)|> render("settings_people.html",site: site,+ dogfood_page_path: "/:dashboard/settings/people",layout: {PlausibleWeb.LayoutView, "site_settings.html"})end@@ -206,10 +206,10 @@ defmodule PlausibleWeb.SiteController doshared_links = Repo.all(from l in Plausible.Site.SharedLink, where: l.site_id == ^site.id)conn- |> assign(:skip_plausible_tracking, true)|> render("settings_visibility.html",site: site,shared_links: shared_links,+ dogfood_page_path: "/:dashboard/settings/visibility",layout: {PlausibleWeb.LayoutView, "site_settings.html"})end@@ -218,9 +218,9 @@ defmodule PlausibleWeb.SiteController dosite = conn.assigns[:site] |> Repo.preload(:custom_domain)conn- |> assign(:skip_plausible_tracking, true)|> render("settings_goals.html",site: site,+ dogfood_page_path: "/:dashboard/settings/goals",connect_live_socket: true,layout: {PlausibleWeb.LayoutView, "site_settings.html"})@@ -233,6 +233,7 @@ defmodule PlausibleWeb.SiteController do|> assign(:skip_plausible_tracking, true)|> render("settings_funnels.html",site: site,+ dogfood_page_path: "/:dashboard/settings/funnels",connect_live_socket: true,layout: {PlausibleWeb.LayoutView, "site_settings.html"})@@ -245,6 +246,7 @@ defmodule PlausibleWeb.SiteController do|> assign(:skip_plausible_tracking, true)|> render("settings_props.html",site: site,+ dogfood_page_path: "/:dashboard/settings/properties",layout: {PlausibleWeb.LayoutView, "site_settings.html"},connect_live_socket: true)@@ -261,10 +263,10 @@ defmodule PlausibleWeb.SiteController doendconn- |> assign(:skip_plausible_tracking, true)|> render("settings_search_console.html",site: site,search_console_domains: search_console_domains,+ dogfood_page_path: "/:dashboard/settings/search-console",layout: {PlausibleWeb.LayoutView, "site_settings.html"})end@@ -273,12 +275,12 @@ defmodule PlausibleWeb.SiteController dosite = conn.assigns[:site] |> Repo.preload(:custom_domain)conn- |> assign(:skip_plausible_tracking, true)|> render("settings_email_reports.html",site: site,weekly_report: Repo.get_by(Plausible.Site.WeeklyReport, site_id: site.id),monthly_report: Repo.get_by(Plausible.Site.MonthlyReport, site_id: site.id),spike_notification: Repo.get_by(Plausible.Site.SpikeNotification, site_id: site.id),+ dogfood_page_path: "/:dashboard/settings/email-reports",layout: {PlausibleWeb.LayoutView, "site_settings.html"})end@@ -300,9 +302,9 @@ defmodule PlausibleWeb.SiteController dosite = conn.assigns[:site] |> Repo.preload(:custom_domain)conn- |> assign(:skip_plausible_tracking, true)|> render("settings_danger_zone.html",site: site,+ dogfood_page_path: "/:dashboard/settings/danger-zone",layout: {PlausibleWeb.LayoutView, "site_settings.html"})enddiff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.exindex dc21f7cd4c..0434ea39b8 100644--- a/lib/plausible_web/controllers/stats_controller.ex+++ b/lib/plausible_web/controllers/stats_controller.ex@@ -51,14 +51,14 @@ defmodule PlausibleWeb.StatsController dodef stats(%{assigns: %{site: site}} = conn, _params) dostats_start_date = Plausible.Sites.stats_start_date(site)can_see_stats? = not Sites.locked?(site) or conn.assigns[:current_user_role] == :super_admin+ demo = site.domain == PlausibleWeb.Endpoint.host()+ dogfood_page_path = if !demo, do: "/:dashboard"cond dostats_start_date && can_see_stats? ->- demo = site.domain == PlausibleWeb.Endpoint.host()offer_email_report = get_session(conn, site.domain <> "_offer_email_report")conn- |> assign(:skip_plausible_tracking, !demo)|> remove_email_report_banner(site)|> put_resp_header("x-robots-tag", "noindex, nofollow")|> render("stats.html",@@ -72,20 +72,24 @@ defmodule PlausibleWeb.StatsController dooffer_email_report: offer_email_report,demo: demo,flags: get_flags(conn.assigns[:current_user]),- is_dbip: is_dbip()+ is_dbip: is_dbip(),+ dogfood_page_path: dogfood_page_path)!stats_start_date && can_see_stats? ->- conn- |> assign(:skip_plausible_tracking, true)- |> render("waiting_first_pageview.html", site: site)+ render(conn, "waiting_first_pageview.html",+ site: site,+ dogfood_page_path: dogfood_page_path+ )Sites.locked?(site) ->owner = Sites.owner_for(site)- conn- |> assign(:skip_plausible_tracking, true)- |> render("site_locked.html", owner: owner, site: site)+ render(conn, "site_locked.html",+ owner: owner,+ site: site,+ dogfood_page_path: dogfood_page_path+ )endend@@ -234,10 +238,10 @@ defmodule PlausibleWeb.StatsController doelse_e ->conn- |> assign(:skip_plausible_tracking, true)|> render("shared_link_password.html",link: shared_link,- layout: {PlausibleWeb.LayoutView, "focus.html"}+ layout: {PlausibleWeb.LayoutView, "focus.html"},+ dogfood_page_path: "/share/:dashboard")endend@@ -278,11 +282,11 @@ defmodule PlausibleWeb.StatsController do|> redirect(to: "/share/#{URI.encode_www_form(shared_link.site.domain)}?auth=#{slug}")elseconn- |> assign(:skip_plausible_tracking, true)|> render("shared_link_password.html",link: shared_link,error: "Incorrect password. Please try again.",- layout: {PlausibleWeb.LayoutView, "focus.html"}+ layout: {PlausibleWeb.LayoutView, "focus.html"},+ dogfood_page_path: "/share/:dashboard")endelse@@ -294,7 +298,6 @@ defmodule PlausibleWeb.StatsController docond do!shared_link.site.locked ->conn- |> assign(:skip_plausible_tracking, true)|> put_resp_header("x-robots-tag", "noindex, nofollow")|> delete_resp_header("x-frame-options")|> render("stats.html",@@ -307,7 +310,7 @@ defmodule PlausibleWeb.StatsController dotitle: title(conn, shared_link.site),offer_email_report: false,demo: false,- skip_plausible_tracking: true,+ dogfood_page_path: "/share/:dashboard",shared_link_auth: shared_link.slug,embedded: conn.params["embed"] == "true",background: conn.params["background"],@@ -319,9 +322,11 @@ defmodule PlausibleWeb.StatsController doSites.locked?(shared_link.site) ->owner = Sites.owner_for(shared_link.site)- conn- |> assign(:skip_plausible_tracking, true)- |> render("site_locked.html", owner: owner, site: shared_link.site)+ render(conn, "site_locked.html",+ owner: owner,+ site: shared_link.site,+ dogfood_page_path: "/share/:dashboard"+ )endenddiff --git a/lib/plausible_web/templates/auth/register_form.html.eex b/lib/plausible_web/templates/auth/register_form.html.eexindex 9e5c841af5..33cea48ea0 100644--- a/lib/plausible_web/templates/auth/register_form.html.eex+++ b/lib/plausible_web/templates/auth/register_form.html.eex@@ -10,7 +10,7 @@</div><div class="w-full max-w-3xl mt-4 mx-auto flex flex-shrink-0">- <%= form_for @changeset, "/register", [class: "w-full max-w-md mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8", id: "register-form"], fn f -> %>+ <%= form_for @changeset, "/register", [class: "w-full max-w-md mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8 plausible-event-name=Signup"], fn f -> %><h2 class="text-xl font-black dark:text-gray-100">Enter your details</h2><div class="my-4"><%= label f, :name, "Full name", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>diff --git a/lib/plausible_web/templates/auth/register_from_invitation_form.html.eex b/lib/plausible_web/templates/auth/register_from_invitation_form.html.eexindex b5fdef97f0..6f1ae0ba64 100644--- a/lib/plausible_web/templates/auth/register_from_invitation_form.html.eex+++ b/lib/plausible_web/templates/auth/register_from_invitation_form.html.eex@@ -3,7 +3,7 @@<div class="text-xl font-medium">Set up privacy-friendly analytics with just a few clicks</div></div>-<%= form_for @changeset, Routes.auth_path(@conn, :register_from_invitation_form, @invitation.invitation_id), [class: "w-full max-w-md mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8"], fn f -> %>+<%= form_for @changeset, Routes.auth_path(@conn, :register_from_invitation_form, @invitation.invitation_id), [class: "w-full max-w-md mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8", id: "register-via-invitation-form"], fn f -> %><h2 class="text-xl font-black dark:text-gray-100">Enter your details</h2><div class="my-4"><div class="flex justify-between">diff --git a/lib/plausible_web/templates/layout/_tracking.html.eex b/lib/plausible_web/templates/layout/_tracking.html.eexdeleted file mode 100644index 813e90dd93..0000000000--- a/lib/plausible_web/templates/layout/_tracking.html.eex+++ /dev/null@@ -1,9 +0,0 @@-<%= if !Application.get_env(:plausible, :is_selfhost) && [email protected][:skip_plausible_tracking] do %>- <%= if Application.get_env(:plausible, :environment) in ["prod", "staging"] do %>- <script defer data-domain="<%= base_domain() %>" event-logged_in="<%= [email protected][:current_user] %>" src="<%="#{plausible_url()}/js/script.pageview-props.js"%>"></script>- <script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>- <% else %>- <script defer data-domain="<%= base_domain() %>" event-logged_in="<%= [email protected][:current_user] %>" src="<%="#{plausible_url()}/js/plausible.local.pageview-props.js"%>"></script>- <script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>- <% end %>-<% end %>diff --git a/lib/plausible_web/templates/layout/_tracking.html.heex b/lib/plausible_web/templates/layout/_tracking.html.heexnew file mode 100644index 0000000000..5181af6cf3--- /dev/null+++ b/lib/plausible_web/templates/layout/_tracking.html.heex@@ -0,0 +1,20 @@+<%= if !Application.get_env(:plausible, :is_selfhost) && [email protected][:skip_plausible_tracking] do %>+ <script defer data-domain={dogfood_domain(@conn)} src={dogfood_script_url()}>+ </script>+ <script>+ window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }++ <%= if @conn.assigns[:dogfood_page_path] do %>+ const pageUrl = '<%= Path.join(plausible_url(), @conn.assigns[:dogfood_page_path]) %>'+ <% else %>+ const pageUrl = window.location.href+ <% end %>++ plausible('pageview', {+ u: pageUrl,+ props: {+ logged_in: <%= [email protected][:current_user] %>+ }+ })+ </script>+<% end %>diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 7d1361583a..e4b6c6fcfc 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -13,6 +13,22 @@ defmodule PlausibleWeb.LayoutView doPlausibleWeb.Endpoint.websocket_url()end+ def dogfood_script_url() do+ if Application.get_env(:plausible, :environment) in ["prod", "staging"] do+ "#{plausible_url()}/js/script.manual.pageview-props.tagged-events.js"+ else+ "#{plausible_url()}/js/script.local.manual.pageview-props.tagged-events.js"+ end+ end++ def dogfood_domain(conn) do+ if conn.assigns[:embedded] do+ "embed." <> base_domain()+ else+ base_domain()+ end+ end+def home_dest(conn) doif conn.assigns[:current_user] do"/sites"