Skip to content

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

Ensure that question marks are encoded properly for the database

Uku Taht7364733faf54
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6dc17286d7..55e7540461 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.
+
## Unreleased
+### Added
+- Data exported via the download button will contain CSV data for all visible graps in a zip file.
+
+### Fixed
+- Fixes database error when pathname contains a question mark
+
+## v1.4.0
+
### Added
- New parameter `metrics` for the `/api/v1/stats/timeseries` endpoint plausible/analytics#952
- CSV export now includes pageviews, bounce rate and visit duration in addition to visitors plausible/analytics#952
@@ -19,7 +28,6 @@ All notable changes to this project will be documented in this file.
- Add Conversion Rate to Top Sources, Top Pages Devices, Countries when filtered by a goal plausible/analytics#1299
- Add list view for countries report in dashboard plausible/analytics#1381
- Add ability to view more than 100 custom goal properties plausible/analytics#1353
-- Data exported via the download button will contain CSV data for all visible graps in a zip file.
### Fixed
- Fix weekly report time range plausible/analytics#951
diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex
index 284b73f3dc..6cf84f0045 100644
--- a/lib/plausible/stats/base.ex
+++ b/lib/plausible/stats/base.ex
@@ -157,33 +157,30 @@ defmodule Plausible.Stats.Base do
Enum.reduce(Filters.visit_props(), sessions_q, fn prop_name, sessions_q ->
filter = query.filters["visit:" <> prop_name]
- prop_name = Map.get(@api_prop_name_to_db, prop_name, prop_name)
+
+ prop_name =
+ Map.get(@api_prop_name_to_db, prop_name, prop_name)
+ |> String.to_existing_atom()
case filter do
{:is, value} ->
- where_target = [{String.to_existing_atom(prop_name), db_prop_val(prop_name, value)}]
- from(s in sessions_q, where: ^where_target)
+ value = db_prop_val(prop_name, value)
+ from(s in sessions_q, where: fragment("? = ?", field(s, ^prop_name), ^value))
{:is_not, value} ->
- fragment_data = [
- {String.to_existing_atom(prop_name), {:!=, db_prop_val(prop_name, value)}}
- ]
-
- from(s in sessions_q, where: fragment(^fragment_data))
+ value = db_prop_val(prop_name, value)
+ from(s in sessions_q, where: fragment("? != ?", field(s, ^prop_name), ^value))
{:member, values} ->
list = Enum.map(values, &db_prop_val(prop_name, &1))
- fragment_data = [{String.to_existing_atom(prop_name), {:in, list}}]
- from(s in sessions_q, where: fragment(^fragment_data))
+ from(s in sessions_q, where: fragment("? in tuple(?)", field(s, ^prop_name), ^list))
{:matches, expr} ->
regex = page_regex(expr)
- prop_name = String.to_existing_atom(prop_name)
from(s in sessions_q, where: fragment("match(?, ?)", field(s, ^prop_name), ^regex))
{:does_not_match, expr} ->
regex = page_regex(expr)
- prop_name = String.to_existing_atom(prop_name)
from(s in sessions_q, where: fragment("not(match(?, ?))", field(s, ^prop_name), ^regex))
nil ->
@@ -310,11 +307,11 @@ defmodule Plausible.Stats.Base do
end
end
- defp db_prop_val("referrer_source", @no_ref), do: ""
- defp db_prop_val("referrer", @no_ref), do: ""
- defp db_prop_val("utm_medium", @no_ref), do: ""
- defp db_prop_val("utm_source", @no_ref), do: ""
- defp db_prop_val("utm_campaign", @no_ref), do: ""
+ defp db_prop_val(:referrer_source, @no_ref), do: ""
+ defp db_prop_val(:referrer, @no_ref), do: ""
+ defp db_prop_val(:utm_medium, @no_ref), do: ""
+ defp db_prop_val(:utm_source, @no_ref), do: ""
+ defp db_prop_val(:utm_campaign, @no_ref), do: ""
defp db_prop_val(_, val), do: val
defp utc_boundaries(%Query{period: "realtime"}, _timezone) do