Custom Events are not tracked by default - you have to configure them on your site to be sent to Plausible. See examples and learn more in
- <.styled_link href="https://plausible.io/docs/custom-event-goals" new_tab={true}>
+ <.styled_link href="https://plausible.io/docs/scroll-depth" new_tab={true}>
our docs
.
diff --git a/priv/json-schemas/query-api-schema.json b/priv/json-schemas/query-api-schema.json
index 0c95244ce979..76d8b075a378 100644
--- a/priv/json-schemas/query-api-schema.json
+++ b/priv/json-schemas/query-api-schema.json
@@ -272,7 +272,7 @@
},
{
"const": "scroll_depth",
- "$comment": "only :internal"
+ "markdownDescription": "Average page scroll depth. Requires: `event:page` filter or `event:page` dimension"
}
]
},
diff --git a/test/plausible/imported/csv_importer_test.exs b/test/plausible/imported/csv_importer_test.exs
index 2c2f45734782..23730b793e44 100644
--- a/test/plausible/imported/csv_importer_test.exs
+++ b/test/plausible/imported/csv_importer_test.exs
@@ -1164,7 +1164,7 @@ defmodule Plausible.Imported.CSVImporterTest do
]
query_scroll_depth_per_page = fn conn, site ->
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
diff --git a/test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs b/test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs
index c3c92b30ae06..4d06e5abb3e4 100644
--- a/test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs
+++ b/test/plausible_web/controllers/api/external_stats_controller/query_imported_test.exs
@@ -1388,7 +1388,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryImportedTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["visitors", "scroll_depth"],
"date_range" => "all",
@@ -1476,7 +1476,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryImportedTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["visitors", "scroll_depth"],
"date_range" => "all",
@@ -1510,7 +1510,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryImportedTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["visitors", "scroll_depth"],
"date_range" => ["2022-01-01", "2022-01-31"],
@@ -1554,7 +1554,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryImportedTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["visitors", "scroll_depth"],
"date_range" => "all",
diff --git a/test/plausible_web/controllers/api/external_stats_controller/query_test.exs b/test/plausible_web/controllers/api/external_stats_controller/query_test.exs
index 104fa08176be..81c0f99f1605 100644
--- a/test/plausible_web/controllers/api/external_stats_controller/query_test.exs
+++ b/test/plausible_web/controllers/api/external_stats_controller/query_test.exs
@@ -3724,16 +3724,18 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
describe "scroll_depth" do
setup [:create_user, :create_site, :create_api_key, :use_api_key]
- test "scroll depth is (not yet) available in public API", %{conn: conn, site: site} do
+ test "cannot query scroll depth without page filter or dimension", %{conn: conn, site: site} do
conn =
post(conn, "/api/v2/query", %{
"site_id" => site.domain,
- "filters" => [["is", "event:page", ["/"]]],
"date_range" => "all",
"metrics" => ["scroll_depth"]
})
- assert json_response(conn, 400)["error"] =~ "Invalid metric \"scroll_depth\""
+ assert %{"error" => error} = json_response(conn, 400)
+
+ assert error ==
+ "Metric `scroll_depth` can only be queried with event:page filters or dimensions."
end
test "can query scroll_depth metric with a page filter", %{conn: conn, site: site} do
@@ -3747,7 +3749,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"filters" => [["is", "event:page", ["/"]]],
"date_range" => "all",
@@ -3781,7 +3783,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"filters" => [["is", "event:page", ["/"]], ["is", "event:props:author", ["john"]]],
"date_range" => "all",
@@ -3793,13 +3795,13 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
]
end
- test "scroll depth is 0 when no engagement data in range", %{conn: conn, site: site} do
+ test "scroll depth is nil when no engagement data in range", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview, timestamp: ~N[2021-01-01 00:00:00])
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"filters" => [["is", "event:page", ["/"]]],
"date_range" => "all",
@@ -3811,9 +3813,9 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
]
end
- test "scroll depth is 0 when no data at all in range", %{conn: conn, site: site} do
+ test "scroll depth is nil when no data at all in range", %{conn: conn, site: site} do
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"filters" => [["is", "event:page", ["/"]]],
"date_range" => "all",
@@ -3845,7 +3847,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
@@ -3879,7 +3881,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
@@ -3908,7 +3910,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
@@ -3941,7 +3943,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
@@ -4028,7 +4030,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"order_by" => [["scroll_depth", "asc"]],
@@ -4097,7 +4099,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"date_range" => "all",
@@ -4169,7 +4171,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.QueryTest do
])
conn =
- post(conn, "/api/v2/query-internal-test", %{
+ post(conn, "/api/v2/query", %{
"site_id" => site.domain,
"metrics" => ["scroll_depth"],
"order_by" => [["scroll_depth", "desc"]],