Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Fixed summary query.

Mike Cao344ffeb65860
diff --git a/.eslintrc.json b/.eslintrc.json
index 341903f23..1a9f88f69 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -13,7 +13,8 @@
},
"plugins": ["react"],
"rules": {
- "react/react-in-jsx-scope": "off"
+ "react/react-in-jsx-scope": "off",
+ "react/prop-types": "off"
},
"globals": {
"React": "writable"
diff --git a/components/PageviewsChart.js b/components/PageviewsChart.js
index 20d5e02c0..99fa529b0 100644
--- a/components/PageviewsChart.js
+++ b/components/PageviewsChart.js
@@ -15,7 +15,7 @@ export default function PageviewsChart({ data, unit }) {
switch (unit) {
case 'day':
if (n > 7) {
- return index % (n / 15) === 0 ? format(d, 'MMM d') : '';
+ return index % ~~(n / 15) === 0 ? format(d, 'MMM d') : '';
}
return format(d, 'EEE M/d');
default:
diff --git a/package.json b/package.json
index 06fff41e1..7804d7f79 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"cookie": "^0.4.1",
"cors": "^2.8.5",
"date-fns": "^2.14.0",
+ "date-fns-tz": "^1.0.10",
"detect-browser": "^5.1.1",
"dotenv": "^8.2.0",
"formik": "^2.1.5",
diff --git a/pages/api/website/[id]/pageviews.js b/pages/api/website/[id]/pageviews.js
index 99e869490..578fbcbf1 100644
--- a/pages/api/website/[id]/pageviews.js
+++ b/pages/api/website/[id]/pageviews.js
@@ -11,9 +11,12 @@ export default async (req, res) => {
return res.status(400).end();
}
+ const start = new Date(+start_at);
+ const end = new Date(+end_at);
+
const [pageviews, uniques] = await Promise.all([
- getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, '*'),
- getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, 'distinct session_id'),
+ getPageviewData(+id, start, end, tz, unit, '*'),
+ getPageviewData(+id, start, end, tz, unit, 'distinct session_id'),
]);
return res.status(200).json({ pageviews, uniques });
diff --git a/pages/api/website/[id]/summary.js b/pages/api/website/[id]/summary.js
index a1882ad55..c8b95599c 100644
--- a/pages/api/website/[id]/summary.js
+++ b/pages/api/website/[id]/summary.js
@@ -1,6 +1,5 @@
import { getSummary } from 'lib/db';
import { useAuth } from 'lib/middleware';
-import { format } from 'date-fns';
export default async (req, res) => {
await useAuth(req, res);
@@ -9,8 +8,8 @@ export default async (req, res) => {
const summary = await getSummary(
+id,
- format(new Date(+start_at), 'yyyy-MM-dd hh:mm:ss'),
- format(new Date(+end_at), 'yyyy-MM-dd hh:mm:ss'),
+ new Date(+start_at).toISOString(),
+ new Date(+end_at).toISOString(),
);
const stats = Object.keys(summary[0]).reduce((obj, key) => {
diff --git a/yarn.lock b/yarn.lock
index b34196770..f38a23e2d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3007,6 +3007,11 @@ d@1, d@^1.0.1:
es5-ext "^0.10.50"
type "^1.0.1"
+date-fns-tz@^1.0.10:
+ version "1.0.10"
+ resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-1.0.10.tgz#30fef0038f80534fddd8e133a6b8ca55ba313748"
+ integrity sha512-cHQAz0/9uDABaUNDM80Mj1FL4ODlxs1xEY4b0DQuAooO2UdNKvDkNbV8ogLnxLbv02Ru1HXFcot0pVvDRBgptg==
+
date-fns@^2.14.0:
version "2.14.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.14.0.tgz#359a87a265bb34ef2e38f93ecf63ac453f9bc7ba"