Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Connect to live socket only on specific pages (#3292)

hq193a7cd5d4922
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex
index 2f25fad06c..9e929e7f72 100644
--- a/lib/plausible_web/controllers/site_controller.ex
+++ b/lib/plausible_web/controllers/site_controller.ex
@@ -282,6 +282,7 @@ defmodule PlausibleWeb.SiteController do
|> assign(:skip_plausible_tracking, true)
|> render("settings_funnels.html",
site: site,
+ connect_live_socket: true,
layout: {PlausibleWeb.LayoutView, "site_settings.html"}
)
else
@@ -295,7 +296,8 @@ defmodule PlausibleWeb.SiteController do
|> assign(:skip_plausible_tracking, true)
|> render("settings_props.html",
site: conn.assigns.site,
- layout: {PlausibleWeb.LayoutView, "site_settings.html"}
+ layout: {PlausibleWeb.LayoutView, "site_settings.html"},
+ connect_live_socket: true
)
else
conn |> Plug.Conn.put_status(401) |> Plug.Conn.halt()
diff --git a/lib/plausible_web/live/flash.ex b/lib/plausible_web/live/flash.ex
index ee963a667c..ed1008f37a 100644
--- a/lib/plausible_web/live/flash.ex
+++ b/lib/plausible_web/live/flash.ex
@@ -24,6 +24,7 @@ defmodule PlausibleWeb.Live.Flash do
</.flash>
</div>
<div
+ :if={Application.get_env(:plausible, :environment) == "dev"}
id="live-view-connection-status"
class="hidden"
phx-disconnected={JS.show()}
@@ -37,7 +38,7 @@ defmodule PlausibleWeb.Live.Flash do
Oops, a server blip
</:title>
<:message>
- Please wait while we're trying to reconnect...
+ Live socket disconnected.
</:message>
</.flash>
</div>
diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex
index b58a7a2951..f69a98decc 100644
--- a/lib/plausible_web/templates/layout/app.html.eex
+++ b/lib/plausible_web/templates/layout/app.html.eex
@@ -5,11 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Plausible is a lightweight and open-source web analytics tool. Your website data is 100% yours and the privacy of your visitors is respected."/>
- <%= if Plausible.Funnels.enabled_for?(@conn.assigns[:current_user]) do %>
+ <%= if @conn.assigns[:connect_live_socket] do %>
<meta name="csrf-token" content="<%= Plug.CSRFProtection.get_csrf_token() %>" />
<meta name="websocket-url" content="<%= websocket_url() %>" />
- <meta name="robots" content="<%= @conn.private.robots %>" />
<% end %>
+ <meta name="robots" content="<%= @conn.private.robots %>" />
<link rel="icon" type="image/png" sizes="32x32" href="<%= PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_favicon.png") %>">
<link rel="apple-touch-icon" href="/images/icon/apple-touch-icon.png">
<title><%= assigns[:title] || "Plausible · Simple, privacy-friendly alternative to Google Analytics" %></title>