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 { useSelector } from 'react-redux';
import classNames from 'classnames';
import Head from 'next/head';
import Link from 'next/link';
@ -12,11 +13,12 @@ import EventsChart from '../metrics/EventsChart';
import Button from '../common/Button';
import EmptyPlaceholder from '../common/EmptyPlaceholder';
export default function Test() {
export default function TestConsole() {
const user = useSelector(state => state.user);
const [website, setWebsite] = useState();
const { data } = useFetch('/api/websites');
if (!data) {
if (!data || !user?.is_admin) {
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 { url } = filters;
let urlFilter = '';
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 { url } = filters;
let urlFilter = '';
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 { domain, url } = filters;
let domainFilter = '';
let urlFilter = '';
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}%`);
}
@ -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 { url } = filters;
let urlFilter = '';
if (url) {

View File

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

View File

@ -21,7 +21,7 @@ export default async (req, res) => {
const startDate = new Date(+start_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);
}

View File

@ -14,7 +14,7 @@ export default async (req, res) => {
const startDate = new Date(+start_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) => {
obj[key] = Number(metrics[0][key]) || 0;

View File

@ -42,7 +42,7 @@ export default async (req, res) => {
const endDate = new Date(+end_at);
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);
}
@ -54,8 +54,10 @@ export default async (req, res) => {
endDate,
getColumn(type),
getTable(type),
domain,
type !== 'url' ? url : undefined,
{
domain,
url: type !== 'url' && url,
},
);
return ok(res, data);

View File

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