Move dogfooding to full build (#3576)

* Move dogfooding to `extra/`

* Remove unused view functions
pull/3587/head r2023.12.04-268
hq1 3 years ago committed by GitHub
parent 466958ea60
commit 74675f0cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -1,25 +1,27 @@
<%= if full_build?() && !@conn.assigns[: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 !@conn.assigns[: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: <%= !!@conn.assigns[:current_user] %>
}
})
</script>
plausible('pageview', {
u: pageUrl,
props: {
logged_in: <%= is_map(@conn.assigns[:current_user]) %>
}
})
</script>
<% end %>
<% end %>

@ -4,14 +4,6 @@ defmodule PlausibleWeb.AuthView do
require Plausible.Billing.Subscription.Status
alias 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"

@ -1,14 +1,6 @@
defmodule PlausibleWeb.BillingView do
use PlausibleWeb, :view
def base_domain do
PlausibleWeb.Endpoint.host()
end
def plausible_url do
PlausibleWeb.Endpoint.url()
end
def present_date(date) do
Date.from_iso8601!(date)
|> Timex.format!("{D} {Mshort} {YYYY}")
@ -17,20 +9,4 @@ defmodule PlausibleWeb.BillingView do
def 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
end
end

@ -6,10 +6,6 @@ defmodule PlausibleWeb.EmailView do
PlausibleWeb.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()},"
end

@ -4,10 +4,6 @@ defmodule PlausibleWeb.LayoutView do
import PlausibleWeb.Components.Billing
def base_domain do
PlausibleWeb.Endpoint.host()
end
def plausible_url do
PlausibleWeb.Endpoint.url()
end
@ -16,32 +12,6 @@ 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
@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 do
use Joken.Config
end

@ -6,18 +6,6 @@ defmodule PlausibleWeb.SiteView do
PlausibleWeb.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) do
Plausible.Sites.shared_link_url(site, link)
end
@ -37,54 +25,4 @@ defmodule PlausibleWeb.SiteView do
"a " <> word
end
end
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>
"""
end
end

@ -2,10 +2,6 @@ defmodule PlausibleWeb.StatsView do
use PlausibleWeb, :view
use Plausible
def base_domain do
PlausibleWeb.Endpoint.host()
end
def plausible_url do
PlausibleWeb.Endpoint.url()
end

Loading…
Cancel
Save