Skip to content

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

Remove featured funnel (#6379)

Adrian Gruntkowskie5890dbbf666
diff --git a/assets/js/dashboard/extra/exploration.js b/assets/js/dashboard/extra/exploration.js
index 3785fc4019..a2ee5a9e8a 100644
--- a/assets/js/dashboard/extra/exploration.js
+++ b/assets/js/dashboard/extra/exploration.js
@@ -34,8 +34,6 @@ const PAGE_FILTER_KEYS = ['page', 'entry_page', 'exit_page']
const MAX_VISIBLE_CANDIDATES = 10
const MIN_GRID_COLUMNS = 3
-const PRELOAD_MAX_STEPS = 2
-const PRELOAD_MAX_CANDIDATES = MAX_VISIBLE_CANDIDATES
const EMPTY_JOURNEY_STATE = {
steps: [],
@@ -155,14 +153,6 @@ function fetchNextWithFunnel(
)
}
-function fetchFeaturedFunnel(site, dashboardState) {
- return api.post(
- url.apiPath(site, '/exploration/featured-funnel'),
- dashboardState,
- { max_steps: PRELOAD_MAX_STEPS, max_candidates: PRELOAD_MAX_CANDIDATES }
- )
-}
-
// x-coordinate of a column element's left or right edge in the coordinate
// space of the scroll container, stable across horizontal scrolling.
function columnEdgeX(colEl, side, containerRect, scrollLeft) {
@@ -576,8 +566,8 @@ function ExplorationColumn({
onFilterChange(e.target.value)
)
- // When a step is selected but there are no candidate results, e.g. from a
- // preloaded journey, synthesise a single-item list from the funnel data so
+ // When a step is selected but there are no candidate results,
+ // synthesise a single-item list from the funnel data so
// the selected step is still rendered in the column.
const listItems =
selected && results.length === 0
@@ -698,12 +688,6 @@ function useExplorationData(site, dashboardState, inViewport) {
// on a context switch, so without this the SVG paths would be stale.
const [layoutKey, setLayoutKey] = useState(0)
- // Track whether the initial preload has fired and whether the most recent
- // funnel data came from that preload, so we skip an immediately redundant
- // funnel refetch.
- const preloadFiredRef = useRef(false)
- const funnelFromPreloadRef = useRef(false)
-
// Ref-copies of the previous dependency values so the main effect can detect
// which dimension changed without adding them to the dep array.
const prevStepsRef = useRef(state.steps)
@@ -829,126 +813,7 @@ function useExplorationData(site, dashboardState, inViewport) {
setActiveLoading(true)
- // On first render fire the featured-funnel preload. Once the preload
- // resolves it sets steps and funnel, which re-triggers this effect for
- // the active-column candidate fetch.
- if (!preloadFiredRef.current) {
- preloadFiredRef.current = true
-
- fetchFeaturedFunnel(site, dashboardState)
- .then((response) => {
- if (isStale()) return
- if (response?.funnel?.length > 0) {
- funnelFromPreloadRef.current = true
- setState((prev) => ({
- ...prev,
- steps: response.funnel.map(({ step }) => step),
- funnel: response.funnel,
- frozen: response.candidates ?? {},
- rateLimited: false
- }))
- // The preload populates steps, which re-triggers this effect for
- // the active-column candidate fetch, so leave loading=true.
- } else {
- // No featured funnel found; fall back to plain candidates for column 0.
- fetchNextWithFunnel(
- site,
- dashboardState,
- [],
- '',
- currentDirection,
- false
- )
- .then((r) => {
- if (!isStale())
- setState((prev) => ({
- ...prev,
- activeResults: maybeEmptyResults(
- r?.next ?? [],
- prev.activeFilter,
- journeyEndEvent
- ),
- rateLimited: false
- }))
- })
- .catch((err) => {
- if (!isStale()) {
- if (isRateLimitedError(err)) {
- setState((prev) => ({
- ...prev,
- rateLimited: true,
- activeResults: []
- }))
- } else {
- setState((prev) => ({ ...prev, activeResults: [] }))
- }
- }
- })
- .finally(() => {
- if (!isStale()) setActiveLoading(false)
- })
- }
- })
- .catch((err) => {
- if (isStale()) return
- if (isRateLimitedError(err)) {
- setState((prev) => ({
- ...prev,
- rateLimited: true,
- activeResults: []
- }))
- setActiveLoading(false)
- return
- }
- fetchNextWithFunnel(
- site,
- dashboardState,
- [],
- '',
- currentDirection,
- false
- )
- .then((r) => {
- if (!isStale())
- setState((prev) => ({
- ...prev,
- activeResults: maybeEmptyResults(
- r?.next ?? [],
- prev.activeFilter,
- journeyEndEvent
- ),
- rateLimited: false
- }))
- })
- .catch((err) => {
- if (!isStale()) {
- if (isRateLimitedError(err)) {
- setState((prev) => ({
- ...prev,
- rateLimited: true,
- activeResults: []
- }))
- } else {
- setState((prev) => ({ ...prev, activeResults: [] }))
- }
- }
- })
- .finally(() => {
- if (!isStale()) setActiveLoading(false)
- })
- })
-
- return
- }
-
- // On subsequent renders fetch next steps and, if the journey changed,
- // also refetch the funnel.
-
- const funnelAlreadyLoaded = funnelFromPreloadRef.current
- funnelFromPreloadRef.current = false
-
- const includeFunnel =
- journeyChanged && steps.length > 0 && !funnelAlreadyLoaded
+ const includeFunnel = journeyChanged && steps.length > 0
if (journeyChanged && steps.length === 0) {
setState((prev) => ({ ...prev, funnel: [] }))
diff --git a/e2e/tests/dashboard/exploration.spec.ts b/e2e/tests/dashboard/exploration.spec.ts
index 827ec28dfd..09203a9928 100644
--- a/e2e/tests/dashboard/exploration.spec.ts
+++ b/e2e/tests/dashboard/exploration.spec.ts
@@ -6,10 +6,7 @@ const getReport = (page: Page) => page.getByTestId('report-behaviours')
const getExplorationTabButton = (report: Locator) =>
tabButton(report, 'Explore')
-test('load featured funnel with only a single step', async ({
- page,
- request
-}) => {
+test('load user journey', async ({ page, request }) => {
const report = getReport(page)
const explorationTabButton = getExplorationTabButton(report)
const { domain } = await setupSite({ page, request })
@@ -54,11 +51,18 @@ test('load featured funnel with only a single step', async ({
).toHaveText(['1'])
await expect(secondColumn).toHaveText(/1 step after/)
+ await expect(secondColumn).toHaveText(/Select a starting point to continue/)
+
+ await firstColumn.getByRole('button', { name: '/page' }).click()
+
+ await expect(
+ firstColumn.getByRole('button', { name: '/page' })
+ ).toHaveAttribute('data-exploration-step', '0')
+
await expect(secondColumn).toHaveText(/No further steps found/)
})
-// current version is often stuck loading if the timing is unlucky
-test('load featured funnel and switch to a period with no events without waiting for load', async ({
+test('load user journey and switch to a period with no events without waiting for load', async ({
page,
request
}) => {
@@ -94,7 +98,7 @@ test('load featured funnel and switch to a period with no events without waiting
await expect(report).toHaveText(/No data yet/)
})
-test('load featured funnel and switch to a period with no events', async ({
+test('load user journey and switch to a period with no events', async ({
page,
request
}) => {
@@ -138,7 +142,7 @@ test('load featured funnel and switch to a period with no events', async ({
await expect(report).toHaveText(/No data yet/)
})
-test('load a 3-step featured funnel', async ({ page, request }) => {
+test('explore a 3-step funnel', async ({ page, request }) => {
const report = getReport(page)
const explorationTabButton = getExplorationTabButton(report)
const { domain } = await setupSite({ page, request })
@@ -215,6 +219,24 @@ test('load a 3-step featured funnel', async ({ page, request }) => {
const secondColumn = report.getByTestId('exploration-column-1')
const thirdColumn = report.getByTestId('exploration-column-2')
+ await firstColumn.getByRole('button', { name: '/home' }).click()
+
+ await expect(
+ firstColumn.getByRole('button', { name: '/home' })
+ ).toHaveAttribute('data-exploration-step', '0')
+
+ await secondColumn.getByRole('button', { name: '/login' }).click()
+
+ await expect(
+ secondColumn.getByRole('button', { name: '/login' })
+ ).toHaveAttribute('data-exploration-step', '1')
+
+ await thirdColumn.getByRole('button', { name: '/dashboard' }).click()
+
+ await expect(
+ thirdColumn.getByRole('button', { name: '/dashboard' })
+ ).toHaveAttribute('data-exploration-step', '2')
+
await expect(firstColumn).toBeVisible()
await expect(secondColumn).toBeVisible()
await expect(thirdColumn).toBeVisible()
@@ -249,7 +271,7 @@ test('load a 3-step featured funnel', async ({ page, request }) => {
await expect(
thirdColumn.getByRole('button', { name: '/dashboard' })
- ).not.toHaveAttribute('data-exploration-step')
+ ).toHaveAttribute('data-exploration-step', '2')
await expect(
thirdColumn.getByTestId('exploration-row').getByTestId('metric-value')
@@ -347,8 +369,6 @@ test('select entries in a 1-step journey', async ({ page, request }) => {
report.getByTestId('exploration-direction-forward')
).toBeVisible()
- await report.getByTestId('exploration-deselect-all').click()
-
const firstColumn = report.getByTestId('exploration-column-0')
const secondColumn = report.getByTestId('exploration-column-1')
@@ -590,8 +610,6 @@ test('select entries in a 3-step journey', async ({ page, request }) => {
report.getByTestId('exploration-direction-forward')
).toBeVisible()
- await report.getByTestId('exploration-deselect-all').click()
-
const firstColumn = report.getByTestId('exploration-column-0')
const secondColumn = report.getByTestId('exploration-column-1')
const thirdColumn = report.getByTestId('exploration-column-2')
@@ -738,8 +756,6 @@ test('explore journey hitting 20 step limit', async ({ page, request }) => {
report.getByTestId('exploration-direction-forward')
).toBeVisible()
- await report.getByTestId('exploration-deselect-all').click()
-
const firstColumn = report.getByTestId('exploration-column-0')
const lastColumn = report.getByTestId('exploration-column-20')
@@ -1070,6 +1086,18 @@ test('change filters during a 3-step journey', async ({ page, request }) => {
const thirdColumn = report.getByTestId('exploration-column-2')
const fourthColumn = report.getByTestId('exploration-column-3')
+ await firstColumn.getByRole('button', { name: '/home' }).click()
+
+ await expect(
+ firstColumn.getByRole('button', { name: '/home' })
+ ).toHaveAttribute('data-exploration-step', '0')
+
+ await secondColumn.getByRole('button', { name: '/login' }).click()
+
+ await expect(
+ secondColumn.getByRole('button', { name: '/login' })
+ ).toHaveAttribute('data-exploration-step', '1')
+
await thirdColumn.getByRole('button', { name: '/dashboard' }).click()
await expect(
diff --git a/extra/lib/plausible/stats/exploration.ex b/extra/lib/plausible/stats/exploration.ex
index e1ea1b0c1b..0c89694a60 100644
--- a/extra/lib/plausible/stats/exploration.ex
+++ b/extra/lib/plausible/stats/exploration.ex
@@ -95,127 +95,6 @@ defmodule Plausible.Stats.Exploration do
|> then(&{:ok, &1})
end
- @doc """
- Builds a "teaser" funnel by greedily selecting steps.
-
- We currently don't know what the "featured" funnel might be,
- but blindly following the most visited cascade, oftentimes results with
- a repetitive back and forth between two pages.
-
- Therefore we start with the most visited entry and
- iteratively pick the most popular next step, that hasn't appeared
- in the journey yet. Trailing slashes are ignored when
- comparing pathnames (e.g. `/foo` and `/foo/` are treated as
- the same page - we should probably do that when deduplicating step candidates too).
-
- ## Options
-
- * `:max_steps` - maximum number of funnel steps to build (default: `6`)
- * `:max_candidates` - passed to `next_steps/3`, limiting
- how many candidate next steps are fetched per step (default: `10`)
- * `:include_wildcard?` - passed to `next_steps/3`, deciding whether
- to include implicit wildcard pathnames in suggestions or not
- (default: true)
- """
- @spec featured_funnel(Plausible.Site.t(), Query.t(), keyword()) ::
- {:ok, %{funnel: [funnel_step()], candidates: [next_step()]}} | {:error, :not_found}
- def featured_funnel(site, query, opts \\ []) do
- max_steps = min(Keyword.get(opts, :max_steps, 6), @max_steps)
- max_candidates = min(Keyword.get(opts, :max_candidates, 10), @max_candidates)
-
- include_wildcard? =
- Keyword.get(
- opts,
- :include_wildcard?,
- Keyword.fetch!(@next_steps_defaults, :include_wildcard?)
- )
-
- with {:ok, result} <-
- build_featured_journey(site, query, max_steps, max_candidates, include_wildcard?),
- {:ok, funnel} <- journey_funnel(query, result.journey) do
- {:ok, %{funnel: funnel, candidates: result.candidates}}
- end
- end
-
- defp build_featured_journey(site, query, max_steps, max_candidates, include_wildcard?) do
- case do_build_journey(
- site,
- query,
- [],
- [],
- MapSet.new([{Journey.Step.journey_end_event(), ""}]),
- max_steps,
- max_candidates,
- include_wildcard?
- ) do
- %{journey: []} -> {:error, :not_found}
- result -> {:ok, result}
- end
- end
-
- defp do_build_journey(
- _site,
- _query,
- journey,
- step_candidates,
- _seen,
- max_steps,
- _max_candidates,
- _include_wildcard?
- )
- when length(journey) >= max_steps do
- %{journey: journey, candidates: step_candidates}
- end
-
- defp do_build_journey(
- site,
- query,
- journey,
- step_candidates,
- seen,
- max_steps,
- max_candidates,
- include_wildcard?
- ) do
- {:ok, candidates} =
- next_steps(site, query, journey,
- max_candidates: max_candidates,
- include_wildcard?: include_wildcard?
- )
-
- case find_unseen_step(candidates, seen) do
- nil ->
- %{journey: journey, candidates: step_candidates}
-
- step ->
- new_seen = MapSet.put(seen, normalize_step_key(step))
-
- do_build_journey(
- site,
- query,
- journey ++ [step],
- step_candidates ++ [candidates],
- new_seen,
- max_steps,
- max_candidates,
- include_wildcard?
- )
- end
- end
-
- defp find_unseen_step(candidates, seen) do
- Enum.find_value(candidates, fn %{step: step} ->
- if not MapSet.member?(seen, normalize_step_key(step)), do: step
- end)
- end
-
- defp normalize_step_key(%Journey.Step{name: name, pathname: pathname}) do
- {name, normalize_pathname(pathname)}
- end
-
- defp normalize_pathname("/"), do: "/"
- defp normalize_pathname(pathname), do: String.trim_trailing(pathname, "/")
-
defp filter_eligible_goals(goals) do
Enum.reject(goals, fn g ->
Plausible.Goal.Revenue.revenue?(g) or g.scroll_threshold > -1 or
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex
index 68407c26db..08fde268c4 100644
--- a/lib/plausible_web/controllers/api/stats_controller.ex
+++ b/lib/plausible_web/controllers/api/stats_controller.ex
@@ -30,8 +30,7 @@ defmodule PlausibleWeb.Api.StatsController do
when action in [
:exploration_next,
:exploration_funnel,
- :exploration_next_with_funnel,
- :exploration_featured_funnel
+ :exploration_next_with_funnel
]
end
end
@@ -211,30 +210,6 @@ defmodule PlausibleWeb.Api.StatsController do
end
end
- def exploration_featured_funnel(conn, params) do
- site = conn.assigns.site
-
- case check_exploration_rate_limit(site) do
- :ok ->
- query = Query.from(site, params, debug_metadata: debug_metadata(conn))
-
- include_wildcard? =
- not FunWithFlags.enabled?(@exploration_wildcard_disabled_flag, for: site)
-
- case Exploration.featured_funnel(site, query,
- max_steps: params["max_steps"],
- max_candidates: params["max_candidates"],
- include_wildcard?: include_wildcard?
- ) do
- {:ok, funnel_and_candidates} -> json(conn, funnel_and_candidates)
- {:error, :not_found} -> json(conn, [])
- end
-
- {:error, :rate_limit} ->
- H.too_many_requests(conn, "Too many exploration requests")
- end
- end
-
def exploration_next_with_funnel(conn, %{"journey" => steps} = params) do
site = conn.assigns.site
search_term = params["search_term"] || ""
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index b8213b3a9a..be2c099abe 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -277,10 +277,6 @@ defmodule PlausibleWeb.Router do
post "/:domain/exploration/next-with-funnel",
StatsController,
:exploration_next_with_funnel
-
- post "/:domain/exploration/featured-funnel",
- StatsController,
- :exploration_featured_funnel
end
scope private: %{allow_consolidated_views: true} do
diff --git a/test/plausible/stats/exploration_test.exs b/test/plausible/stats/exploration_test.exs
index 848dfee99d..40c77db74d 100644
--- a/test/plausible/stats/exploration_test.exs
+++ b/test/plausible/stats/exploration_test.exs
@@ -349,135 +349,6 @@ defmodule Plausible.Stats.ExplorationTest do
end
end
- describe "featured_funnel" do
- test "builds a funnel starting with the most visited step", %{site: site} do
- query = QueryBuilder.build!(site, input_date_range: :all)
-
- assert {:ok, %{funnel: [step1, step2, step3, step4]}} =
- Exploration.featured_funnel(site, query)
-
- assert step1.step.pathname == "/home"
- assert step1.visitors == 2
-
- assert step2.step.pathname == "/login"
- assert step2.visitors == 2
-
- assert step3.step.pathname == "/docs"
- assert step3.visitors == 1
-
- assert step4.step.pathname == "/logout"
- assert step4.visitors == 1
- end
-
- test "limits the funnel to max_steps", %{site: site} do
- query = QueryBuilder.build!(site, input_date_range: :all)
-
- assert {:ok, %{funnel: [step1, step2]}} =
- Exploration.featured_funnel(site, query, max_steps: 2)
-
- assert step1.step.pathname == "/home"
- assert step2.step.pathname == "/login"
- end
-
- test "returns error when no events exist" do
- empty_site = new_site()
- query = QueryBuilder.build!(empty_site, input_date_range: :all)
-
- assert {:error, :not_found} = Exploration.featured_funnel(empty_site, query)
- end
-
- test "stops when no more unseen steps are available" do
- site = new_site()
- now = DateTime.utc_now()
-
- populate_stats(site, [
- build(:pageview,
- user_id: 123,
- pathname: "/only-page",
- timestamp: DateTime.shift(now, minute: -30)
- )
- ])
-
- query = QueryBuilder.build!(site, input_date_range: :all)
-
- assert {:ok, %{funnel: [step1]}} =
- Exploration.featured_funnel(site, query, max_steps: 6)
-
- assert step1.step.pathname == "/only-page"
- assert step1.visitors == 1
- end
-
- test "respects query filters", %{site: site} do
- query =
- QueryBuilder.build!(site,
- input_date_range: :all,
- filters: [[:is, "visit:browser", ["Firefox"]]]
- )
-
- assert {:ok, result} = Exploration.featured_funnel(site, query)
-
- pathnames = Enum.map(result.funnel, & &1.step.pathname)
- assert pathnames == ["/docs", "/logout"]
- end
-
- test "does not revisit already-seen steps in a cycle" do
- site = new_site()
- now = DateTime.utc_now()
-
- populate_stats(site, [
- # user 123
- build(:pageview,
- user_id: 123,
- pathname: "/a",
- timestamp: DateTime.shift(now, minute: -50)
- ),
- build(:pageview,
- user_id: 123,
- pathname: "/b",
- timestamp: DateTime.shift(now, minute: -40)
- ),
- build(:pageview,
- user_id: 123,
- pathname: "/a",
- timestamp: DateTime.shift(now, minute: -30)
- ),
- build(:pageview,
- user_id: 123,
- pathname: "/b",
- timestamp: DateTime.shift(now, minute: -20)
- ),
- build(:pageview,
- user_id: 123,
- pathname: "/c",
- timestamp: DateTime.shift(now, minute: -10)
- ),
- # user 124
- build(:pageview,
- user_id: 124,
- pathname: "/a",
- timestamp: DateTime.shift(now, minute: -50)
- ),
- build(:pageview,
- user_id: 124,
- pathname: "/b",
- timestamp: DateTime.shift(now, minute: -40)
- ),
- build(:pageview,
- user_id: 124,
- pathname: "/c",
- timestamp: DateTime.shift(now, minute: -30)
- )
- ])
-
- query = QueryBuilder.build!(site, input_date_range: :all)
-
- assert {:ok, result} = Exploration.featured_funnel(site, query)
-
- pathnames = Enum.map(result.funnel, & &1.step.pathname)
- assert pathnames == ["/a", "/b", "/c"]
- end
- end
-
describe "next_steps" do
test "suggests the next step for a 2-step journey", %{site: site} do
query = QueryBuilder.build!(site, input_date_range: :all)
diff --git a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs b/test/plausible_web/controllers/api/stats_controller/exploration_test.exs
index b69617f2a9..d5c7e4a44c 100644
--- a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/exploration_test.exs
@@ -486,21 +486,6 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest do
assert json_response(resp, 429) == %{"error" => "Too many exploration requests"}
end
- test "returns 429 for exploration_featured_funnel when rate limit exceeded", %{
- conn: conn,
- site: site
- } do
- exhaust_exploration_rate_limit(site)
-
- resp =
- conn
- |> post("/api/stats/#{site.domain}/exploration/featured-funnel/", %{
- "period" => "all"
- })
-
- assert json_response(resp, 429) == %{"error" => "Too many exploration requests"}
- end
-
test "returns 429 for exploration_next_with_funnel when rate limit exceeded", %{
conn: conn,
site: site