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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
use uuid
Brian Caoc147742d7adb
diff --git a/components/metrics/ActiveUsers.js b/components/metrics/ActiveUsers.jsindex 0ab266d3f..6b7c47791 100644--- a/components/metrics/ActiveUsers.js+++ b/components/metrics/ActiveUsers.js@@ -5,7 +5,7 @@ import useFetch from 'hooks/useFetch';import Dot from 'components/common/Dot';import styles from './ActiveUsers.module.css';-export default function ActiveUsers({ websiteId, className, value, interval = 60000 }) {+export default function ActiveUsers({ websiteId, className, value, interval = 600000 }) {const url = websiteId ? `/websites/${websiteId}/active` : null;const { data } = useFetch(url, {interval,diff --git a/components/metrics/WebsiteHeader.js b/components/metrics/WebsiteHeader.jsindex 15f6d0ff9..1a6bdf159 100644--- a/components/metrics/WebsiteHeader.js+++ b/components/metrics/WebsiteHeader.js@@ -17,8 +17,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal<Favicon domain={domain} /><LinkclassName={styles.titleLink}- href="/website/[...id]"- as={`/website/${websiteId}/${title}`}+ href="/websites/[...id]"+ as={`/websites/${websiteId}/${title}`}><OverflowText tooltipId={`${websiteId}-title`}>{title}</OverflowText></Link>@@ -41,8 +41,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal<RefreshButton websiteId={websiteId} />{showLink && (<Link- href="/website/[...id]"- as={`/website/${websiteId}/${title}`}+ href="/websites/[...id]"+ as={`/websites/${websiteId}/${title}`}className={styles.link}icon={<Arrow />}size="small"diff --git a/components/pages/WebsiteList.js b/components/pages/WebsiteList.jsindex dfd041a15..24ac8bec1 100644--- a/components/pages/WebsiteList.js+++ b/components/pages/WebsiteList.js@@ -27,7 +27,7 @@ export default function WebsiteList({ websites, showCharts, limit }) {const ordered = useMemo(() =>websites- .map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))+ .map(website => ({ ...website, order: websiteOrder.indexOf(website.websiteUuid) || 0 })).sort(firstBy('order')),[websites, websiteOrder],);@@ -46,11 +46,11 @@ export default function WebsiteList({ websites, showCharts, limit }) {return (<div>- {ordered.map(({ id, name, domain }, index) =>+ {ordered.map(({ websiteUuid, name, domain }, index) =>index < limit ? (- <div key={id} className={styles.website}>+ <div key={websiteUuid} className={styles.website}><WebsiteChart- websiteId={id}+ websiteId={websiteUuid}title={name}domain={domain}showChart={showCharts}diff --git a/components/settings/WebsiteSettings.js b/components/settings/WebsiteSettings.jsindex 7e9371f5a..f044bd68b 100644--- a/components/settings/WebsiteSettings.js+++ b/components/settings/WebsiteSettings.js@@ -84,7 +84,7 @@ export default function WebsiteSettings() {);const DetailsLink = ({ id, name, domain }) => (- <Link className={styles.detailLink} href="/website/[...id]" as={`/website/${id}/${name}`}>+ <Link className={styles.detailLink} href="/websites/[...id]" as={`/websites/${id}/${name}`}><Favicon domain={domain} /><OverflowText tooltipId={`${id}-name`}>{name}</OverflowText></Link>diff --git a/pages/api/websites/[id]/active.js b/pages/api/websites/[id]/active.jsindex 20550427d..c29f97016 100644--- a/pages/api/websites/[id]/active.js+++ b/pages/api/websites/[id]/active.js@@ -11,9 +11,7 @@ export default async (req, res) => {return unauthorized(res);}- const { id } = req.query;-- const websiteId = +id;+ const { id: websiteId } = req.query;const result = await getActiveVisitors(websiteId);diff --git a/pages/api/websites/[id]/events.js b/pages/api/websites/[id]/events.jsindex 308e1efc2..c1f96b2e7 100644--- a/pages/api/websites/[id]/events.js+++ b/pages/api/websites/[id]/events.js@@ -14,13 +14,11 @@ export default async (req, res) => {return unauthorized(res);}- const { id, start_at, end_at, unit, tz, url, event_name } = req.query;+ const { id: websiteId, start_at, end_at, unit, tz, url, event_name } = req.query;if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) {return badRequest(res);}-- const websiteId = +id;const startDate = new Date(+start_at);const endDate = new Date(+end_at);diff --git a/pages/api/websites/[id]/index.js b/pages/api/websites/[id]/index.jsindex c6b8779fc..ad55a2967 100644--- a/pages/api/websites/[id]/index.js+++ b/pages/api/websites/[id]/index.js@@ -1,14 +1,10 @@-import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';-import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';import { allowQuery } from 'lib/auth';import { useAuth, useCors } from 'lib/middleware';-import { validate } from 'uuid';+import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';+import { deleteWebsite, getAccount, getWebsite, getWebsiteByUuid, updateWebsite } from 'queries';export default async (req, res) => {- const { id } = req.query;-- const websiteId = +id;- const where = validate(id) ? { websiteUuid: id } : { id: +id };+ const { id: websiteId } = req.query;if (req.method === 'GET') {await useCors(req, res);@@ -17,7 +13,7 @@ export default async (req, res) => {return unauthorized(res);}- const website = await getWebsite(where);+ const website = await getWebsiteByUuid(websiteId);return ok(res, website);}@@ -33,7 +29,7 @@ export default async (req, res) => {account = await getAccount({ accountUuid });}- const website = await getWebsite(where);+ const website = await getWebsite(websiteId);const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;@@ -48,7 +44,7 @@ export default async (req, res) => {shareId: shareId,userId: account ? account.id : +owner,},- where,+ { websiteUuid: websiteId },);return ok(res);diff --git a/pages/api/websites/[id]/metrics.js b/pages/api/websites/[id]/metrics.jsindex 206209c63..29bfdc779 100644--- a/pages/api/websites/[id]/metrics.js+++ b/pages/api/websites/[id]/metrics.js@@ -1,8 +1,8 @@-import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'queries';-import { ok, methodNotAllowed, unauthorized, badRequest } from 'next-basics';import { allowQuery } from 'lib/auth';-import { useCors } from 'lib/middleware';import { FILTER_IGNORED } from 'lib/constants';+import { useCors } from 'lib/middleware';+import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';+import { getPageviewMetrics, getSessionMetrics, getWebsiteByUuid } from 'queries';const sessionColumns = ['browser', 'os', 'device', 'screen', 'country', 'language'];const pageviewColumns = ['url', 'referrer', 'query'];@@ -41,9 +41,19 @@ export default async (req, res) => {return unauthorized(res);}- const { id, type, start_at, end_at, url, referrer, os, browser, device, country } = req.query;+ const {+ id: websiteId,+ type,+ start_at,+ end_at,+ url,+ referrer,+ os,+ browser,+ device,+ country,+ } = req.query;- const websiteId = +id;const startDate = new Date(+start_at);const endDate = new Date(+end_at);@@ -83,7 +93,7 @@ export default async (req, res) => {let domain;if (type === 'referrer') {- const website = await getWebsiteById(websiteId);+ const website = await getWebsiteByUuid(websiteId);if (!website) {return badRequest(res);diff --git a/pages/api/websites/[id]/pageviews.js b/pages/api/websites/[id]/pageviews.jsindex f00fffa18..acf7f11bc 100644--- a/pages/api/websites/[id]/pageviews.js+++ b/pages/api/websites/[id]/pageviews.js@@ -14,10 +14,20 @@ export default async (req, res) => {return unauthorized(res);}- const { id, start_at, end_at, unit, tz, url, referrer, os, browser, device, country } =- req.query;+ const {+ id: websiteId,+ start_at,+ end_at,+ unit,+ tz,+ url,+ referrer,+ os,+ browser,+ device,+ country,+ } = req.query;- const websiteId = +id;const startDate = new Date(+start_at);const endDate = new Date(+end_at);diff --git a/pages/api/websites/[id]/reset.js b/pages/api/websites/[id]/reset.jsindex 2f5d05b47..acfc9b0e3 100644--- a/pages/api/websites/[id]/reset.js+++ b/pages/api/websites/[id]/reset.js@@ -3,8 +3,7 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';import { allowQuery } from 'lib/auth';export default async (req, res) => {- const { id } = req.query;- const websiteId = +id;+ const { id: websiteId } = req.query;if (req.method === 'POST') {if (!(await allowQuery(req))) {diff --git a/pages/api/websites/[id]/stats.js b/pages/api/websites/[id]/stats.jsindex ee1403f8b..c127eb0fd 100644--- a/pages/api/websites/[id]/stats.js+++ b/pages/api/websites/[id]/stats.js@@ -11,9 +11,18 @@ export default async (req, res) => {return unauthorized(res);}- const { website_id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;+ const {+ id: websiteId,+ start_at,+ end_at,+ url,+ referrer,+ os,+ browser,+ device,+ country,+ } = req.query;- const websiteId = +website_id;const startDate = new Date(+start_at);const endDate = new Date(+end_at);diff --git a/queries/analytics/event/getEventMetrics.js b/queries/analytics/event/getEventMetrics.jsindex 447e1cc84..edf5de8c2 100644--- a/queries/analytics/event/getEventMetrics.js+++ b/queries/analytics/event/getEventMetrics.js@@ -23,11 +23,13 @@ async function relationalQuery(return rawQuery(`selectevent_name x,- ${getDateQuery('created_at', unit, timezone)} t,+ ${getDateQuery('event.created_at', unit, timezone)} t,count(*) yfrom event- where website_id=$1- and created_at between $2 and $3+ join website+ on event.website_id = website.website_id+ where website_uuid='${websiteId}'+ and event.created_at between $2 and $3${getFilterQuery('event', filters, params)}group by 1, 2order by 2`,diff --git a/queries/analytics/pageview/getPageviewMetrics.js b/queries/analytics/pageview/getPageviewMetrics.jsindex 80a4e957c..e1c4d43f9 100644--- a/queries/analytics/pageview/getPageviewMetrics.js+++ b/queries/analytics/pageview/getPageviewMetrics.js@@ -22,8 +22,9 @@ async function relationalQuery(websiteId, { startDate, endDate, column, table, freturn rawQuery(`select ${column} x, count(*) yfrom ${table}+ ${` join website on ${table}.website_id = website.website_id`}${joinSession}- where ${table}.website_id=$1+ where website.website_uuid='${websiteId}'and ${table}.created_at between $2 and $3${pageviewQuery}${joinSession && sessionQuery}diff --git a/queries/analytics/pageview/getPageviewParams.js b/queries/analytics/pageview/getPageviewParams.jsindex bf0d6b5eb..8ec26dec8 100644--- a/queries/analytics/pageview/getPageviewParams.js+++ b/queries/analytics/pageview/getPageviewParams.js@@ -22,8 +22,9 @@ async function relationalQuery(websiteId, start_at, end_at, column, table, filte`select url x,count(*) yfrom ${table}+ ${` join website on ${table}.website_id = website.website_id`}${joinSession}- where ${table}.website_id=$1+ where website.website_uuid='${websiteId}'and ${table}.created_at between $2 and $3and ${table}.url like '%?%'${pageviewQuery}diff --git a/queries/analytics/pageview/getPageviewStats.js b/queries/analytics/pageview/getPageviewStats.jsindex 5a740dbda..ceed4daf0 100644--- a/queries/analytics/pageview/getPageviewStats.js+++ b/queries/analytics/pageview/getPageviewStats.js@@ -34,8 +34,10 @@ async function relationalQuery(`select ${getDateQuery('pageview.created_at', unit, timezone)} t,count(${count !== '*' ? `${count}${sessionKey}` : count}) yfrom pageview+ join website+ on pageview.website_id = website.website_id${joinSession}- where pageview.website_id=$1+ where website.website_uuid='${websiteId}'and pageview.created_at between $2 and $3${pageviewQuery}${sessionQuery}diff --git a/queries/analytics/session/getSessionMetrics.js b/queries/analytics/session/getSessionMetrics.jsindex 7ad7ecfea..cbf3ed589 100644--- a/queries/analytics/session/getSessionMetrics.js+++ b/queries/analytics/session/getSessionMetrics.js@@ -20,8 +20,10 @@ async function relationalQuery(websiteId, { startDate, endDate, field, filters =where x.session_id in (select pageview.session_idfrom pageview+ join website+ on pageview.website_id = website.website_id${joinSession}- where pageview.website_id=$1+ where website.website_uuid='${websiteId}'and pageview.created_at between $2 and $3${pageviewQuery}${sessionQuery}diff --git a/queries/analytics/stats/getActiveVisitors.js b/queries/analytics/stats/getActiveVisitors.jsindex e919760a2..9d6b1f09e 100644--- a/queries/analytics/stats/getActiveVisitors.js+++ b/queries/analytics/stats/getActiveVisitors.js@@ -17,8 +17,10 @@ async function relationalQuery(websiteId) {return prisma.rawQuery(`select count(distinct session_id) xfrom pageview- where website_id = $1- and created_at >= $2`,+ join website+ on pageview.website_id = website.website_id+ where website.website_uuid = '${websiteId}'+ and pageview.created_at >= $2`,params,);}diff --git a/queries/analytics/stats/getWebsiteStats.js b/queries/analytics/stats/getWebsiteStats.jsindex 79156ef15..b6bf7b878 100644--- a/queries/analytics/stats/getWebsiteStats.js+++ b/queries/analytics/stats/getWebsiteStats.js@@ -30,11 +30,13 @@ async function relationalQuery(websiteId, { start_at, end_at, filters = {} }) {count(*) c,${getTimestampInterval('pageview.created_at')} as "time"from pageview+ join website+ on pageview.website_id = website.website_id${joinSession}- where pageview.website_id=$1- and pageview.created_at between $2 and $3- ${pageviewQuery}- ${sessionQuery}+ where website.website_uuid='${websiteId}'+ and pageview.created_at between $2 and $3+ ${pageviewQuery}+ ${sessionQuery}group by 1, 2) t`,params,