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 dogfooding to full build (#3576)
hq174675f0cbc58
diff --git a/extra/lib/plausible_web/dogfood.ex b/extra/lib/plausible_web/dogfood.exnew file mode 100644index 0000000000..df8fd01c40--- /dev/null+++ b/extra/lib/plausible_web/dogfood.ex@@ -0,0 +1,31 @@+defmodule PlausibleWeb.Dogfood do+ @moduledoc """+ Plausible tracking itself functions+ """++ @doc """+ Temporary override to do more testing of the new ingest.plausible.io endpoint for accepting events. In staging and locally+ will fall back to staging.plausible.io/api/event and localhost:8000/api/event respectively.+ """+ def api_destination() do+ if Application.get_env(:plausible, :environment) == "prod" do+ "https://ingest.plausible.io/api/event"+ end+ end++ def script_url() do+ if Application.get_env(:plausible, :environment) in ["prod", "staging"] do+ "#{PlausibleWeb.Endpoint.url()}/js/script.manual.pageview-props.tagged-events.js"+ else+ "#{PlausibleWeb.Endpoint.url()}/js/script.local.manual.pageview-props.tagged-events.js"+ end+ end++ def domain(conn) do+ cond do+ Application.get_env(:plausible, :is_selfhost) -> "ee.plausible.io"+ conn.assigns[:embedded] -> "embed." <> PlausibleWeb.Endpoint.host()+ true -> PlausibleWeb.Endpoint.host()+ end+ end+enddiff --git a/lib/plausible_web/templates/layout/_tracking.html.heex b/lib/plausible_web/templates/layout/_tracking.html.heexindex 2d1ea894a0..a8a398013c 100644--- a/lib/plausible_web/templates/layout/_tracking.html.heex+++ b/lib/plausible_web/templates/layout/_tracking.html.heex@@ -1,25 +1,27 @@-<%= if full_build?() && [email protected][:skip_plausible_tracking] do %>- <script- defer- data-api={dogfood_api_destination()}- data-domain={dogfood_domain(@conn)}- src={dogfood_script_url()}- >- </script>- <script>- window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }+<%= on_full_build do %>+ <%= if [email protected][:skip_plausible_tracking] do %>+ <script+ defer+ data-api={PlausibleWeb.Dogfood.api_destination()}+ data-domain={PlausibleWeb.Dogfood.domain(@conn)}+ src={PlausibleWeb.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 %>+ <%= 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>+ plausible('pageview', {+ u: pageUrl,+ props: {+ logged_in: <%= is_map(@conn.assigns[:current_user]) %>+ }+ })+ </script>+ <% end %><% end %>diff --git a/lib/plausible_web/views/auth_view.ex b/lib/plausible_web/views/auth_view.exindex b7f26d29f8..a3c6d19726 100644--- a/lib/plausible_web/views/auth_view.ex+++ b/lib/plausible_web/views/auth_view.ex@@ -4,14 +4,6 @@ defmodule PlausibleWeb.AuthView dorequire Plausible.Billing.Subscription.Statusalias Plausible.Billing.{Plans, Subscription}- def base_domain do- PlausibleWeb.Endpoint.host()- end-- def plausible_url do- PlausibleWeb.Endpoint.url()- end-def subscription_quota(subscription, options \\ [])def subscription_quota(nil, _options), do: "Free trial"diff --git a/lib/plausible_web/views/billing_view.ex b/lib/plausible_web/views/billing_view.exindex 32a088a0b8..2731dd8f9d 100644--- a/lib/plausible_web/views/billing_view.ex+++ b/lib/plausible_web/views/billing_view.ex@@ -1,14 +1,6 @@defmodule PlausibleWeb.BillingView douse PlausibleWeb, :view- def base_domain do- PlausibleWeb.Endpoint.host()- end-- def plausible_url do- PlausibleWeb.Endpoint.url()- end-def present_date(date) doDate.from_iso8601!(date)|> Timex.format!("{D} {Mshort} {YYYY}")@@ -17,20 +9,4 @@ defmodule PlausibleWeb.BillingView dodef present_currency("USD"), do: "$"def present_currency("EUR"), do: "€"def present_currency("GBP"), do: "£"-- def reccommended_plan(usage) do- cond do- usage < 9000 ->- "10k / mo"-- usage < 90_000 ->- "100k / mo"-- usage < 900_000 ->- "1m / mo"-- true ->- "custom"- end- endenddiff --git a/lib/plausible_web/views/email_view.ex b/lib/plausible_web/views/email_view.exindex e2c6db164c..e74bbe636a 100644--- a/lib/plausible_web/views/email_view.ex+++ b/lib/plausible_web/views/email_view.ex@@ -6,10 +6,6 @@ defmodule PlausibleWeb.EmailView doPlausibleWeb.Endpoint.url()end- def base_domain() do- PlausibleWeb.Endpoint.host()- end-def greet_recipient(%{user: %{name: name}}) when is_binary(name) do"Hey #{String.split(name) |> List.first()},"enddiff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 707b24b387..27976fd82d 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -4,10 +4,6 @@ defmodule PlausibleWeb.LayoutView doimport PlausibleWeb.Components.Billing- def base_domain do- PlausibleWeb.Endpoint.host()- end-def plausible_url doPlausibleWeb.Endpoint.url()end@@ -16,32 +12,6 @@ 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-- @doc """- Temporary override to do more testing of the new ingest.plausible.io endpoint for accepting events. In staging and locally- will fall back to staging.plausible.io/api/event and localhost:8000/api/event respectively.- """- def dogfood_api_destination() do- if Application.get_env(:plausible, :environment) == "prod" do- "https://ingest.plausible.io/api/event"- end- end-defmodule JWT douse Joken.Configenddiff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.exindex b7f97920f9..a3ae89f776 100644--- a/lib/plausible_web/views/site_view.ex+++ b/lib/plausible_web/views/site_view.ex@@ -6,18 +6,6 @@ defmodule PlausibleWeb.SiteView doPlausibleWeb.Endpoint.url()end- def base_domain() do- PlausibleWeb.Endpoint.host()- end-- def goal_name(%Plausible.Goal{page_path: page_path}) when is_binary(page_path) do- "Visit " <> page_path- end-- def goal_name(%Plausible.Goal{event_name: name}) when is_binary(name) do- name- end-def shared_link_dest(site, link) doPlausible.Sites.shared_link_url(site, link)end@@ -37,54 +25,4 @@ defmodule PlausibleWeb.SiteView do"a " <> wordendend-- def google_logo(assigns \\ %{}) do- ~H"""- <svg- width="46px"- height="46px"- viewBox="0 0 46 46"- version="1.1"- xmlns="http://www.w3.org/2000/svg"- xmlns:xlink="http://www.w3.org/1999/xlink"- xmlns:sketch="http://www.bohemiancoding.com/sketch/ns"- >- <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">- <g transform="translate(-1.000000, -1.000000)">- <g transform="translate(15.000000, 15.000000)">- <path- d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z"- id="Shape"- fill="#4285F4"- sketch:type="MSShapeGroup"- >- </path>- <path- d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z"- id="Shape"- fill="#34A853"- sketch:type="MSShapeGroup"- >- </path>- <path- d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z"- id="Shape"- fill="#FBBC05"- sketch:type="MSShapeGroup"- >- </path>- <path- d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z"- id="Shape"- fill="#EA4335"- sketch:type="MSShapeGroup"- >- </path>- <path d="M0,0 L18,0 L18,18 L0,18 L0,0 Z" id="Shape" sketch:type="MSShapeGroup"></path>- </g>- </g>- </g>- </svg>- """- endenddiff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.exindex 70e5e10bd8..0bd9e278c3 100644--- a/lib/plausible_web/views/stats_view.ex+++ b/lib/plausible_web/views/stats_view.ex@@ -2,10 +2,6 @@ defmodule PlausibleWeb.StatsView douse PlausibleWeb, :viewuse Plausible- def base_domain do- PlausibleWeb.Endpoint.host()- end-def plausible_url doPlausibleWeb.Endpoint.url()end