mirror of
https://github.com/plausible/analytics.git
synced 2024-11-30 11:13:22 +03:00
Remove glob filters from API
This commit is contained in:
parent
7bc40a63fe
commit
77d3d8695d
@ -231,14 +231,10 @@ defmodule Plausible.Stats.Query do
|
||||
|
||||
is_negated = String.contains?(str, "!=")
|
||||
is_list = String.contains?(val, "|")
|
||||
is_glob = String.contains?(val, "*")
|
||||
|
||||
cond do
|
||||
is_list && is_glob -> raise "Not implemented"
|
||||
is_negated && is_glob -> {key, {:does_not_match, val}}
|
||||
key == "event:goal" -> {key, parse_goal_filter(val)}
|
||||
is_list -> {key, {:member, String.split(val, "|")}}
|
||||
is_glob -> {key, {:matches, val}}
|
||||
is_negated -> {key, {:is_not, val}}
|
||||
true -> {key, {:is, val}}
|
||||
end
|
||||
|
@ -654,35 +654,6 @@ defmodule PlausibleWeb.Api.ExternalStatsController.AggregateTest do
|
||||
}
|
||||
end
|
||||
|
||||
test "can filter by page regex", %{conn: conn, site: site} do
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
pathname: "/"
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog/post1"
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog/post1"
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog/post2"
|
||||
)
|
||||
])
|
||||
|
||||
conn =
|
||||
get(conn, "/api/v1/stats/aggregate", %{
|
||||
"site_id" => site.domain,
|
||||
"period" => "day",
|
||||
"metrics" => "visitors",
|
||||
"filters" => "event:page==/blog/**"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200)["results"] == %{
|
||||
"visitors" => %{"value" => 3}
|
||||
}
|
||||
end
|
||||
|
||||
test "filtering by event:name", %{conn: conn, site: site} do
|
||||
populate_stats([
|
||||
build(:event,
|
||||
|
@ -1334,65 +1334,5 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "negated glob filter for pages", %{conn: conn, site: site} do
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
pathname: "/blog/ignore",
|
||||
domain: site.domain
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog",
|
||||
domain: site.domain
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/plausible.io",
|
||||
domain: site.domain
|
||||
)
|
||||
])
|
||||
|
||||
conn =
|
||||
get(conn, "/api/v1/stats/breakdown", %{
|
||||
"site_id" => site.domain,
|
||||
"property" => "event:page",
|
||||
"filters" => "event:page!=/blog**"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"results" => [
|
||||
%{"page" => "/plausible.io", "visitors" => 1}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "negated glob filter for sources", %{conn: conn, site: site} do
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
pathname: "/blog/ignore",
|
||||
referrer_source: "Should not show"
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog",
|
||||
referrer_source: "Should not show"
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/plausible.io",
|
||||
referrer_source: "Google"
|
||||
)
|
||||
])
|
||||
|
||||
conn =
|
||||
get(conn, "/api/v1/stats/breakdown", %{
|
||||
"site_id" => site.domain,
|
||||
"property" => "visit:source",
|
||||
"filters" => "event:page!=/blog**"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"results" => [
|
||||
%{"source" => "Google", "visitors" => 1}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -797,42 +797,5 @@ defmodule PlausibleWeb.Api.ExternalStatsController.TimeseriesTest do
|
||||
assert first == %{"date" => "2021-01-01", "visitors" => 2}
|
||||
assert second == %{"date" => "2021-01-02", "visitors" => 1}
|
||||
end
|
||||
|
||||
test "filter with negated glob for pages", %{conn: conn, site: site} do
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
pathname: "/",
|
||||
timestamp: ~N[2021-01-01 00:00:00]
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog",
|
||||
timestamp: ~N[2021-01-01 00:00:00]
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/plausible.io",
|
||||
timestamp: ~N[2021-01-02 00:00:00]
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/",
|
||||
timestamp: ~N[2021-01-02 00:00:00]
|
||||
),
|
||||
build(:pageview,
|
||||
pathname: "/blog/ignore",
|
||||
timestamp: ~N[2021-01-02 00:00:00]
|
||||
)
|
||||
])
|
||||
|
||||
conn =
|
||||
get(conn, "/api/v1/stats/timeseries", %{
|
||||
"site_id" => site.domain,
|
||||
"period" => "month",
|
||||
"date" => "2021-01-01",
|
||||
"filters" => "event:page!=/blog**"
|
||||
})
|
||||
|
||||
%{"results" => [first, second | _rest]} = json_response(conn, 200)
|
||||
assert first == %{"date" => "2021-01-01", "visitors" => 1}
|
||||
assert second == %{"date" => "2021-01-02", "visitors" => 2}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user