Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Expose exploration endpoints via POST (#6248)
Adam Rutkowski8c3d67480b65
diff --git a/assets/js/dashboard/api.ts b/assets/js/dashboard/api.tsindex 198d0d9d33..d51aa2ae80 100644--- a/assets/js/dashboard/api.ts+++ b/assets/js/dashboard/api.ts@@ -54,6 +54,13 @@ export function dashboardStateToSearchParams(dashboardState: DashboardState,extraQuery: unknown[] = []): string {+ return serializeUrlParams(dashboardStateToParams(dashboardState, extraQuery))+}++export function dashboardStateToParams(+ dashboardState: DashboardState,+ extraQuery: unknown[] = []+): Record<string, string> {const queryObj: Record<string, string> = {}if (dashboardState.period) {queryObj.period = dashboardState.period@@ -92,7 +99,7 @@ export function dashboardStateToSearchParams(Object.assign(queryObj, ...extraQuery)- return serializeUrlParams(queryObj)+ return queryObj}function getHeaders(): Record<string, string> {@@ -149,6 +156,28 @@ export async function get(return handleApiResponse(response)}+export async function post(+ url: string,+ dashboardState: DashboardState,+ ...extraBodyParams: unknown[]+) {+ const queryString = serializeUrlParams(getSharedLinkSearchParams())+ const response = await fetch(queryString ? `${url}?${queryString}` : url, {+ method: 'POST',+ signal: abortController.signal,+ headers: {+ ...getHeaders(),+ 'Content-Type': 'application/json',+ Accept: 'application/json'+ },+ body: JSON.stringify(+ dashboardStateToParams(dashboardState, [...extraBodyParams])+ )+ })++ return handleApiResponse(response)+}+export const mutation = async <TBody extends Record<string, unknown> = Record<string, unknown>>(diff --git a/assets/js/dashboard/stats/exploration.js b/assets/js/dashboard/stats/exploration.jsindex 31921e8a85..c5e1a789ba 100644--- a/assets/js/dashboard/stats/exploration.js+++ b/assets/js/dashboard/stats/exploration.js@@ -34,7 +34,7 @@ function fetchColumnData(site, dashboardState, steps, filter, direction) {const stateToUse = stateWithApplicableFilters(dashboardState, steps)const journey = toJourney(steps)- return api.get(url.apiPath(site, '/exploration/next'), stateToUse, {+ return api.post(url.apiPath(site, '/exploration/next'), stateToUse, {journey: JSON.stringify(journey),search_term: filter,direction@@ -45,7 +45,7 @@ function fetchFunnelData(site, dashboardState, steps, direction) {const stateToUse = stateWithApplicableFilters(dashboardState, steps)const journey = toJourney(steps)- return api.get(url.apiPath(site, '/exploration/funnel'), stateToUse, {+ return api.post(url.apiPath(site, '/exploration/funnel'), stateToUse, {journey: JSON.stringify(journey),direction})diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.exindex d353f28380..d6d9775227 100644--- a/lib/plausible_web/router.ex+++ b/lib/plausible_web/router.ex@@ -282,8 +282,8 @@ defmodule PlausibleWeb.Router doget "/:domain/funnels/:id", StatsController, :funnelend- get "/:domain/exploration/next", StatsController, :exploration_next- get "/:domain/exploration/funnel", StatsController, :exploration_funnel+ post "/:domain/exploration/next", StatsController, :exploration_next+ post "/:domain/exploration/funnel", StatsController, :exploration_funnelscope private: %{allow_consolidated_views: true} dopost "/:domain/query", StatsController, :querydiff --git a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs b/test/plausible_web/controllers/api/stats_controller/exploration_test.exsindex e3af2e5613..6e633bfcf4 100644--- a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs+++ b/test/plausible_web/controllers/api/stats_controller/exploration_test.exs@@ -71,7 +71,10 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest doresp =conn- |> get("/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&period=24h")+ |> post("/api/stats/#{site.domain}/exploration/next/", %{+ "journey" => journey,+ "period" => "24h"+ })|> json_response(200)assert [next_step1, next_step2, next_step3] = resp@@ -92,9 +95,11 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest doresp =conn- |> get(- "/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&search_term=doc&period=24h"- )+ |> post("/api/stats/#{site.domain}/exploration/next/", %{+ "journey" => journey,+ "search_term" => "doc",+ "period" => "24h"+ })|> json_response(200)assert [next_step] = resp@@ -107,9 +112,11 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest doresp =conn- |> get(- "/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&direction=backward&period=24h"- )+ |> post("/api/stats/#{site.domain}/exploration/next/", %{+ "journey" => journey,+ "direction" => "backward",+ "period" => "24h"+ })|> json_response(200)assert [next_step1, next_step2] = resp@@ -131,7 +138,10 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest doresp =conn- |> get("/api/stats/#{site.domain}/exploration/funnel/?journey=#{journey}&period=24h")+ |> post("/api/stats/#{site.domain}/exploration/funnel/", %{+ "journey" => journey,+ "period" => "24h"+ })|> json_response(200)assert [step1, step2, step3] = resp@@ -160,9 +170,11 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest doresp =conn- |> get(- "/api/stats/#{site.domain}/exploration/funnel/?journey=#{journey}&direction=backward&period=24h"- )+ |> post("/api/stats/#{site.domain}/exploration/funnel/", %{+ "journey" => journey,+ "direction" => "backward",+ "period" => "24h"+ })|> json_response(200)assert [step1, step2, step3] = resp