Updated query filters. Updated packages.

This commit is contained in:
Mike Cao 2020-09-28 20:23:42 -07:00
parent 6bb34cd3a5
commit 11d8b19279
7 changed files with 35 additions and 17 deletions

View File

@ -1,4 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import classNames from 'classnames'; import classNames from 'classnames';
import Head from 'next/head'; import Head from 'next/head';
import Link from 'next/link'; import Link from 'next/link';
@ -12,11 +13,12 @@ import EventsChart from '../metrics/EventsChart';
import Button from '../common/Button'; import Button from '../common/Button';
import EmptyPlaceholder from '../common/EmptyPlaceholder'; import EmptyPlaceholder from '../common/EmptyPlaceholder';
export default function Test() { export default function TestConsole() {
const user = useSelector(state => state.user);
const [website, setWebsite] = useState(); const [website, setWebsite] = useState();
const { data } = useFetch('/api/websites'); const { data } = useFetch('/api/websites');
if (!data) { if (!data || !user?.is_admin) {
return null; return null;
} }

View File

@ -285,8 +285,9 @@ export async function createAccount(data) {
); );
} }
export function getMetrics(website_id, start_at, end_at, url) { export function getMetrics(website_id, start_at, end_at, filters = {}) {
const params = [website_id, start_at, end_at]; const params = [website_id, start_at, end_at];
const { url } = filters;
let urlFilter = ''; let urlFilter = '';
if (url) { if (url) {
@ -348,8 +349,10 @@ export function getPageviews(
); );
} }
export function getSessionMetrics(website_id, start_at, end_at, field, url) { export function getSessionMetrics(website_id, start_at, end_at, field, filters = {}) {
const params = [website_id, start_at, end_at]; const params = [website_id, start_at, end_at];
const { url } = filters;
let urlFilter = ''; let urlFilter = '';
if (url) { if (url) {
@ -375,13 +378,15 @@ export function getSessionMetrics(website_id, start_at, end_at, field, url) {
); );
} }
export function getPageviewMetrics(website_id, start_at, end_at, field, table, domain, url) { export function getPageviewMetrics(website_id, start_at, end_at, field, table, filters = {}) {
const params = [website_id, start_at, end_at]; const params = [website_id, start_at, end_at];
const { domain, url } = filters;
let domainFilter = ''; let domainFilter = '';
let urlFilter = ''; let urlFilter = '';
if (domain) { if (domain) {
domainFilter = `and referrer not like $${params.length + 1}`; domainFilter = `and referrer not like $${params.length + 1} and referrer not like '/%'`;
params.push(`%${domain}%`); params.push(`%${domain}%`);
} }
@ -420,8 +425,17 @@ export function getActiveVisitors(website_id) {
); );
} }
export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit = 'day', url) { export function getEvents(
website_id,
start_at,
end_at,
timezone = 'utc',
unit = 'day',
filters = {},
) {
const params = [website_id, start_at, end_at]; const params = [website_id, start_at, end_at];
const { url } = filters;
let urlFilter = ''; let urlFilter = '';
if (url) { if (url) {

View File

@ -1,6 +1,6 @@
{ {
"name": "umami", "name": "umami",
"version": "0.59.0", "version": "0.60.0",
"description": "A simple, fast, website analytics alternative to Google Analytics. ", "description": "A simple, fast, website analytics alternative to Google Analytics. ",
"author": "Mike Cao <mike@mikecao.com>", "author": "Mike Cao <mike@mikecao.com>",
"license": "MIT", "license": "MIT",
@ -66,7 +66,7 @@
"is-localhost-ip": "^1.4.0", "is-localhost-ip": "^1.4.0",
"isbot-fast": "^1.2.0", "isbot-fast": "^1.2.0",
"jose": "^2.0.2", "jose": "^2.0.2",
"maxmind": "^4.1.4", "maxmind": "^4.2.0",
"moment-timezone": "^0.5.31", "moment-timezone": "^0.5.31",
"next": "^9.5.3", "next": "^9.5.3",
"react": "^16.13.1", "react": "^16.13.1",
@ -113,7 +113,7 @@
"rollup": "^2.28.2", "rollup": "^2.28.2",
"rollup-plugin-hashbang": "^2.2.2", "rollup-plugin-hashbang": "^2.2.2",
"rollup-plugin-terser": "^7.0.2", "rollup-plugin-terser": "^7.0.2",
"stylelint": "^13.7.1", "stylelint": "^13.7.2",
"stylelint-config-css-modules": "^2.2.0", "stylelint-config-css-modules": "^2.2.0",
"stylelint-config-prettier": "^8.0.1", "stylelint-config-prettier": "^8.0.1",
"stylelint-config-recommended": "^3.0.0", "stylelint-config-recommended": "^3.0.0",

View File

@ -21,7 +21,7 @@ export default async (req, res) => {
const startDate = new Date(+start_at); const startDate = new Date(+start_at);
const endDate = new Date(+end_at); const endDate = new Date(+end_at);
const events = await getEvents(websiteId, startDate, endDate, tz, unit, url); const events = await getEvents(websiteId, startDate, endDate, tz, unit, { url });
return ok(res, events); return ok(res, events);
} }

View File

@ -14,7 +14,7 @@ export default async (req, res) => {
const startDate = new Date(+start_at); const startDate = new Date(+start_at);
const endDate = new Date(+end_at); const endDate = new Date(+end_at);
const metrics = await getMetrics(websiteId, startDate, endDate, url); const metrics = await getMetrics(websiteId, startDate, endDate, { url });
const stats = Object.keys(metrics[0]).reduce((obj, key) => { const stats = Object.keys(metrics[0]).reduce((obj, key) => {
obj[key] = Number(metrics[0][key]) || 0; obj[key] = Number(metrics[0][key]) || 0;

View File

@ -42,7 +42,7 @@ export default async (req, res) => {
const endDate = new Date(+end_at); const endDate = new Date(+end_at);
if (sessionColumns.includes(type)) { if (sessionColumns.includes(type)) {
const data = await getSessionMetrics(websiteId, startDate, endDate, type, url); const data = await getSessionMetrics(websiteId, startDate, endDate, type, { url });
return ok(res, data); return ok(res, data);
} }
@ -54,8 +54,10 @@ export default async (req, res) => {
endDate, endDate,
getColumn(type), getColumn(type),
getTable(type), getTable(type),
{
domain, domain,
type !== 'url' ? url : undefined, url: type !== 'url' && url,
},
); );
return ok(res, data); return ok(res, data);

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import Layout from 'components/layout/Layout'; import Layout from 'components/layout/Layout';
import Test from 'components/pages/Test'; import TestConsole from 'components/pages/TestConsole';
import useRequireLogin from 'hooks/useRequireLogin'; import useRequireLogin from 'hooks/useRequireLogin';
export default function TestPage() { export default function TestPage() {
@ -12,7 +12,7 @@ export default function TestPage() {
return ( return (
<Layout> <Layout>
<Test /> <TestConsole />
</Layout> </Layout>
); );
} }