mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
Skip breakdown of imported pages with pageviews=0 (#3655)
* Skip breakdown of imported pages with pageviews=0 * Fixup * Prove good impoted records are merged
This commit is contained in:
parent
73923404b0
commit
8be9397199
@ -368,6 +368,7 @@ defmodule Plausible.Stats.Imported do
|
|||||||
|
|
||||||
defp select_imported_metrics(q, [:pageviews | rest]) do
|
defp select_imported_metrics(q, [:pageviews | rest]) do
|
||||||
q
|
q
|
||||||
|
|> where([i], i.pageviews > 0)
|
||||||
|> select_merge([i], %{pageviews: sum(i.pageviews)})
|
|> select_merge([i], %{pageviews: sum(i.pageviews)})
|
||||||
|> select_imported_metrics(rest)
|
|> select_imported_metrics(rest)
|
||||||
end
|
end
|
||||||
|
@ -523,6 +523,53 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "pageviews breakdown by event:page - imported data having pageviews=0 and visitors=n should be bypassed",
|
||||||
|
%{conn: conn, site: site} do
|
||||||
|
site =
|
||||||
|
site
|
||||||
|
|> Plausible.Site.start_import(~D[2005-01-01], Timex.today(), "Google Analytics", "ok")
|
||||||
|
|> Plausible.Repo.update!()
|
||||||
|
|
||||||
|
populate_stats(site, [
|
||||||
|
build(:pageview, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
|
||||||
|
build(:pageview, pathname: "/", timestamp: ~N[2021-01-01 00:25:00]),
|
||||||
|
build(:pageview,
|
||||||
|
pathname: "/plausible.io",
|
||||||
|
timestamp: ~N[2021-01-01 00:00:00]
|
||||||
|
),
|
||||||
|
build(:imported_pages,
|
||||||
|
page: "/skip-me",
|
||||||
|
date: ~D[2021-01-01],
|
||||||
|
visitors: 1,
|
||||||
|
pageviews: 0
|
||||||
|
),
|
||||||
|
build(:imported_pages,
|
||||||
|
page: "/include-me",
|
||||||
|
date: ~D[2021-01-01],
|
||||||
|
visitors: 1,
|
||||||
|
pageviews: 1
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
conn =
|
||||||
|
get(conn, "/api/v1/stats/breakdown", %{
|
||||||
|
"site_id" => site.domain,
|
||||||
|
"period" => "day",
|
||||||
|
"date" => "2021-01-01",
|
||||||
|
"property" => "event:page",
|
||||||
|
"with_imported" => "true",
|
||||||
|
"metrics" => "pageviews"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{
|
||||||
|
"results" => [
|
||||||
|
%{"page" => "/", "pageviews" => 2},
|
||||||
|
%{"page" => "/plausible.io", "pageviews" => 1},
|
||||||
|
%{"page" => "/include-me", "pageviews" => 1}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
test "breakdown by event:page", %{conn: conn, site: site} do
|
test "breakdown by event:page", %{conn: conn, site: site} do
|
||||||
populate_stats(site, [
|
populate_stats(site, [
|
||||||
build(:pageview, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
|
build(:pageview, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
|
||||||
|
Loading…
Reference in New Issue
Block a user