mirror of
https://github.com/plausible/analytics.git
synced 2024-12-27 03:21:37 +03:00
Pass interval param to CSV export (#2469)
This commit adds the interval param to the CSV export client-side request.
This commit is contained in:
parent
32a38fac7a
commit
ffbfb14714
@ -233,7 +233,9 @@ class LineGraph extends React.Component {
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
const endpoint = `/${encodeURIComponent(this.props.site.domain)}/export${api.serializeQuery(this.props.query)}`
|
||||
const interval = this.props.graphData?.interval || this.state.interval
|
||||
const queryParams = api.serializeQuery(this.props.query, [{ interval }])
|
||||
const endpoint = `/${encodeURIComponent(this.props.site.domain)}/export${queryParams}`
|
||||
|
||||
return (
|
||||
<a className="w-4 h-4 mx-2" href={endpoint} download onClick={this.downloadSpinner.bind(this)}>
|
||||
|
@ -102,6 +102,32 @@ defmodule PlausibleWeb.StatsControllerTest do
|
||||
conn = get(conn, "/" <> site.domain <> "/export?date=2021-10-20")
|
||||
assert_zip(conn, "30d")
|
||||
end
|
||||
|
||||
test "exports data grouped by interval", %{conn: conn, site: site} do
|
||||
populate_exported_stats(site)
|
||||
conn = get(conn, "/" <> site.domain <> "/export?date=2021-10-20&period=30d&interval=week")
|
||||
|
||||
assert response = response(conn, 200)
|
||||
{:ok, zip} = :zip.unzip(response, [:memory])
|
||||
|
||||
{_filename, visitors} =
|
||||
Enum.find(zip, fn {filename, _data} -> filename == 'visitors.csv' end)
|
||||
|
||||
parsed_csv =
|
||||
visitors
|
||||
|> String.split("\r\n")
|
||||
|> Enum.map(&String.split(&1, ","))
|
||||
|
||||
assert parsed_csv == [
|
||||
["date", "visitors", "pageviews", "bounce_rate", "visit_duration"],
|
||||
["2021-09-20", "1", "1", "100", "0"],
|
||||
["2021-09-27", "0", "0", "", ""],
|
||||
["2021-10-04", "0", "0", "", ""],
|
||||
["2021-10-11", "0", "0", "", ""],
|
||||
["2021-10-18", "3", "3", "67", "20"],
|
||||
[""]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /:website/export - via shared link" do
|
||||
|
Loading…
Reference in New Issue
Block a user