Move dogfooding to full build (#3576)
* Move dogfooding to `extra/` * Remove unused view functionspull/3587/head r2023.12.04-268
parent
466958ea60
commit
74675f0cbc
@ -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 %>
|
||||
|
||||
Loading…
Reference in New Issue