Dogfooding improvements (#3290)

* Simplify tracking script template

* Track dashboard pages with anonymized URLs

* Track embedded dashboards as domain embed. + base_domain

* Add dogfood page ids for dashboard settings

* Add tracking to invitation form

* Start tracking register-via-invitation flow with custom event

* Remove leftover code

* Track logged-in status

* Add verified routes

* Inline dogfood routes

* Path -> Url

* Mix format

* Remove verified routes

* Inline dogfood_path
pull/3358/head^2
Uku Taht 3 years ago committed by GitHub
parent 8c605865b6
commit be1a679933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 });
})
}

@ -98,13 +98,13 @@ defmodule PlausibleWeb.AuthController do
render(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"}
)
else
render(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"}
)
end
end
@ -142,7 +142,7 @@ defmodule PlausibleWeb.AuthController do
invitation: invitation,
changeset: changeset,
layout: {PlausibleWeb.LayoutView, "focus.html"},
skip_plausible_tracking: true
dogfood_page_path: "/register/invitation/:invitation_id"
)
end
else
@ -151,7 +151,7 @@ defmodule PlausibleWeb.AuthController do
changeset: 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"
)
end
end

@ -179,11 +179,11 @@ defmodule PlausibleWeb.SiteController do
end
conn
|> 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 do
shared_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 do
site = 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 do
end
conn
|> 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 do
site = 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 do
site = 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"}
)
end

@ -51,14 +51,14 @@ defmodule PlausibleWeb.StatsController do
def stats(%{assigns: %{site: site}} = conn, _params) do
stats_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 do
stats_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 do
offer_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
)
end
end
@ -234,10 +238,10 @@ defmodule PlausibleWeb.StatsController do
else
_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"
)
end
end
@ -278,11 +282,11 @@ defmodule PlausibleWeb.StatsController do
|> redirect(to: "/share/#{URI.encode_www_form(shared_link.site.domain)}?auth=#{slug}")
else
conn
|> 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"
)
end
else
@ -294,7 +298,6 @@ defmodule PlausibleWeb.StatsController do
cond 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 do
title: 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 do
Sites.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"
)
end
end

@ -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" %>

@ -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">

@ -1,9 +0,0 @@
<%= if !Application.get_env(:plausible, :is_selfhost) && !@conn.assigns[:skip_plausible_tracking] do %>
<%= if Application.get_env(:plausible, :environment) in ["prod", "staging"] do %>
<script defer data-domain="<%= base_domain() %>" event-logged_in="<%= !!@conn.assigns[: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="<%= !!@conn.assigns[: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 %>

@ -0,0 +1,20 @@
<%= if !Application.get_env(:plausible, :is_selfhost) && !@conn.assigns[: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: <%= !!@conn.assigns[:current_user] %>
}
})
</script>
<% end %>

@ -13,6 +13,22 @@ defmodule PlausibleWeb.LayoutView do
PlausibleWeb.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) do
if conn.assigns[:current_user] do
"/sites"

Loading…
Cancel
Save