Skip to content

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

Remove allowed props list from dashboard data attribute (#3230)

Vini Brasil1fedaf18c3e2
diff --git a/assets/js/dashboard/mount.js b/assets/js/dashboard/mount.js
index fb47512572..f135ed3dff 100644
--- a/assets/js/dashboard/mount.js
+++ b/assets/js/dashboard/mount.js
@@ -19,8 +19,8 @@ if (container) {
conversionsEnabled: container.dataset.conversionsEnabled === 'true',
funnelsEnabled: container.dataset.funnelsEnabled === 'true',
propsEnabled: container.dataset.propsEnabled === 'true',
+ hasProps: container.dataset.hasProps === 'true',
funnels: JSON.parse(container.dataset.funnels),
- allowedEventProps: JSON.parse(container.dataset.allowedEventProps),
statsBegin: container.dataset.statsBegin,
nativeStatsBegin: container.dataset.nativeStatsBegin,
embedded: container.dataset.embedded,
diff --git a/assets/js/dashboard/stats/behaviours/index.js b/assets/js/dashboard/stats/behaviours/index.js
index 913a39743f..cccf0bc592 100644
--- a/assets/js/dashboard/stats/behaviours/index.js
+++ b/assets/js/dashboard/stats/behaviours/index.js
@@ -166,8 +166,8 @@ export default function Behaviours(props) {
}
function renderProps() {
- if (site.allowedEventProps && site.allowedEventProps.length > 0) {
- return <Properties site={site} query={query} allowedEventProps={site.allowedEventProps}/>
+ if (site.hasProps) {
+ return <Properties site={site} query={props.query} />
} else if (adminAccess) {
return (
<FeatureSetupNotice
diff --git a/lib/plausible/props.ex b/lib/plausible/props.ex
index 178fef17f9..7410149420 100644
--- a/lib/plausible/props.ex
+++ b/lib/plausible/props.ex
@@ -119,4 +119,11 @@ defmodule Plausible.Props do
defp valid?(key) do
String.length(key) in 1..@max_prop_key_length
end
+
+ @doc """
+ Returns whether the site has configured custom props or not.
+ """
+ def configured?(%Plausible.Site{allowed_event_props: allowed_event_props}) do
+ is_list(allowed_event_props) && length(allowed_event_props) > 0
+ end
end
diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex
index ca5035eeae..19087125e9 100644
--- a/lib/plausible_web/controllers/stats_controller.ex
+++ b/lib/plausible_web/controllers/stats_controller.ex
@@ -65,7 +65,7 @@ defmodule PlausibleWeb.StatsController do
site: site,
has_goals: Plausible.Sites.has_goals?(site),
funnels: Plausible.Funnels.list(site),
- allowed_event_props: site.allowed_event_props,
+ has_props: Plausible.Props.configured?(site),
stats_start_date: stats_start_date,
native_stats_start_date: NaiveDateTime.to_date(site.native_stats_start_at),
title: title(conn, site),
@@ -309,7 +309,7 @@ defmodule PlausibleWeb.StatsController do
site: shared_link.site,
has_goals: Sites.has_goals?(shared_link.site),
funnels: Plausible.Funnels.list(shared_link.site),
- allowed_event_props: shared_link.site.allowed_event_props,
+ has_props: Plausible.Props.configured?(shared_link.site),
stats_start_date: shared_link.site.stats_start_date,
native_stats_start_date: NaiveDateTime.to_date(shared_link.site.native_stats_start_at),
title: title(conn, shared_link.site),
diff --git a/lib/plausible_web/templates/stats/stats.html.eex b/lib/plausible_web/templates/stats/stats.html.eex
index a8f896fcd3..973a912881 100644
--- a/lib/plausible_web/templates/stats/stats.html.eex
+++ b/lib/plausible_web/templates/stats/stats.html.eex
@@ -22,7 +22,7 @@
data-funnels-enabled="<%= @site.funnels_enabled %>"
data-props-enabled="<%= @site.props_enabled %>"
data-funnels="<%= Jason.encode!(@funnels) %>"
- data-allowed-event-props="<%= Jason.encode!(@allowed_event_props) %>"
+ data-has-props="<%= @has_props %>"
data-logged-in="<%= [email protected][:current_user] %>"
data-stats-begin="<%= @stats_start_date %>"
data-native-stats-begin="<%= @native_stats_start_date %>"
diff --git a/test/plausible/props_test.exs b/test/plausible/props_test.exs
index e9a028d697..e488ecdba8 100644
--- a/test/plausible/props_test.exs
+++ b/test/plausible/props_test.exs
@@ -241,4 +241,15 @@ defmodule Plausible.PropsTest do
assert ["first_time_customer", "logged_in", "with_error"] ==
site |> Plausible.Props.suggest_keys_to_allow() |> Enum.sort()
end
+
+ test "configured?/1 returns whether the site has allow at least one prop" do
+ site = insert(:site)
+ refute Plausible.Props.configured?(site)
+
+ {:ok, site} = Plausible.Props.allow(site, "hello-world")
+ assert Plausible.Props.configured?(site)
+
+ {:ok, site} = Plausible.Props.disallow(site, "hello-world")
+ refute Plausible.Props.configured?(site)
+ end
end