mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 11:44:03 +03:00
Skip rows with empty dates from GA imports (#2359)
This commit is contained in:
parent
9a61a10273
commit
e48851a9ed
@ -3,6 +3,8 @@ defmodule Plausible.Imported do
|
||||
use Timex
|
||||
require Logger
|
||||
|
||||
@missing_values ["(none)", "(not set)", "(not provided)", "(other)"]
|
||||
|
||||
@tables ~w(
|
||||
imported_visitors imported_sources imported_pages imported_entry_pages
|
||||
imported_exit_pages imported_locations imported_devices imported_browsers
|
||||
@ -18,7 +20,13 @@ defmodule Plausible.Imported do
|
||||
def from_google_analytics(nil, _site_id, _metric), do: nil
|
||||
|
||||
def from_google_analytics(data, site_id, table) do
|
||||
Enum.map(data, fn row -> new_from_google_analytics(site_id, table, row) end)
|
||||
Enum.reduce(data, [], fn row, acc ->
|
||||
if Map.get(row.dimensions, "ga:date") in @missing_values do
|
||||
acc
|
||||
else
|
||||
[new_from_google_analytics(site_id, table, row) | acc]
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
defp parse_number(nr) do
|
||||
@ -165,7 +173,6 @@ defmodule Plausible.Imported do
|
||||
|> NaiveDateTime.to_date()
|
||||
end
|
||||
|
||||
@missing_values ["(none)", "(not set)", "(not provided)"]
|
||||
defp default_if_missing(value, default \\ nil)
|
||||
defp default_if_missing(value, default) when value in @missing_values, do: default
|
||||
defp default_if_missing(value, _default), do: value
|
||||
|
@ -941,5 +941,65 @@ defmodule Plausible.ImportedTest do
|
||||
|
||||
assert visit_duration["value"] == 3_479_033
|
||||
end
|
||||
|
||||
test "skips empty dates from import", %{conn: conn, site: site} do
|
||||
import_data(
|
||||
[
|
||||
%{
|
||||
dimensions: %{"ga:date" => "20210101"},
|
||||
metrics: %{
|
||||
"ga:users" => "1",
|
||||
"ga:pageviews" => "1",
|
||||
"ga:bounces" => "0",
|
||||
"ga:sessions" => "1",
|
||||
"ga:sessionDuration" => "60"
|
||||
}
|
||||
},
|
||||
%{
|
||||
dimensions: %{"ga:date" => "(other)"},
|
||||
metrics: %{
|
||||
"ga:users" => "1",
|
||||
"ga:pageviews" => "1",
|
||||
"ga:bounces" => "0",
|
||||
"ga:sessions" => "1",
|
||||
"ga:sessionDuration" => "60"
|
||||
}
|
||||
}
|
||||
],
|
||||
site.id,
|
||||
"imported_visitors"
|
||||
)
|
||||
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/top-stats?period=month&date=2021-01-01&with_imported=true"
|
||||
)
|
||||
|
||||
assert %{
|
||||
"top_stats" => [
|
||||
%{
|
||||
"change" => 100,
|
||||
"name" => "Unique visitors",
|
||||
"value" => 1
|
||||
},
|
||||
%{
|
||||
"change" => 100,
|
||||
"name" => "Total pageviews",
|
||||
"value" => 1
|
||||
},
|
||||
%{
|
||||
"change" => nil,
|
||||
"name" => "Bounce rate",
|
||||
"value" => 0
|
||||
},
|
||||
%{
|
||||
"change" => 100,
|
||||
"name" => "Visit duration",
|
||||
"value" => 60
|
||||
}
|
||||
]
|
||||
} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user