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.

add redis placeholder

Brian Cao10cc6616c5d4
diff --git a/lib/session.js b/lib/session.js
index b90e88f7d..8ad83d769 100644
--- a/lib/session.js
+++ b/lib/session.js
@@ -1,6 +1,8 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'queries';
import { getJsonBody, getClientInfo } from 'lib/request';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
+import { runAnalyticsQuery } from 'lib/db';
+import { RELATIONAL, CLICKHOUSE } from 'lib/constants';
export async function getSession(req) {
const { payload } = getJsonBody(req);
@@ -9,7 +11,6 @@ export async function getSession(req) {
throw new Error('Invalid request');
}
- const { website: website_uuid, hostname, screen, language } = payload;
const cache = req.headers['x-umami-cache'];
if (cache) {
@@ -20,24 +21,30 @@ export async function getSession(req) {
}
}
+ const { website: website_uuid, hostname, screen, language } = payload;
+
if (!isValidUuid(website_uuid)) {
throw new Error(`Invalid website: ${website_uuid}`);
}
- const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
-
const website = await getWebsiteByUuid(website_uuid);
if (!website) {
throw new Error(`Website not found: ${website_uuid}`);
}
+ const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
+
const { website_id } = website;
const session_uuid = uuid(website_id, hostname, ip, userAgent);
- let session = await getSessionByUuid(session_uuid);
+ // logic placeholder for redis
+ runAnalyticsQuery({
+ [RELATIONAL]: () => {},
+ [CLICKHOUSE]: () => {},
+ });
- console.log('session here!: ', session);
+ let session = await getSessionByUuid(session_uuid);
if (!session) {
try {
diff --git a/pages/api/collect.js b/pages/api/collect.js
index 4b9763195..472af4214 100644
--- a/pages/api/collect.js
+++ b/pages/api/collect.js
@@ -93,38 +93,3 @@ export default async (req, res) => {
return send(res, token);
};
-
-// async function relational(req, res) {
-// await useSession(req, res);
-
-// const {
-// session: { website_id, session_id, session_uuid },
-// } = req;
-
-// const { type, payload } = getJsonBody(req);
-
-// let { url, referrer, event_name, event_data } = payload;
-
-// if (process.env.REMOVE_TRAILING_SLASH) {
-// url = removeTrailingSlash(url);
-// }
-
-// const event_uuid = uuid();
-
-// if (type === 'pageview') {
-// await savePageView(website_id, { session_id, session_uuid, url, referrer });
-// } else if (type === 'event') {
-// await saveEvent(website_id, {
-// event_uuid,
-// session_id,
-// session_uuid,
-// url,
-// event_name,
-// event_data,
-// });
-// } else {
-// return badRequest(res);
-// }
-// }
-
-// function clickhouse() {}