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.

Updated id logic.

Mike Caoe8a933f80e70
diff --git a/src/app/api/send/route.ts b/src/app/api/send/route.ts
index 6edab2a28..1fffdac4a 100644
--- a/src/app/api/send/route.ts
+++ b/src/app/api/send/route.ts
@@ -18,7 +18,6 @@ const schema = z.object({
payload: z.object({
website: z.string().uuid(),
data: anyObjectParam.optional(),
- id: z.string().optional(),
hostname: z.string().max(100).optional(),
language: z.string().max(35).optional(),
referrer: urlOrPathParam.optional(),
@@ -30,6 +29,7 @@ const schema = z.object({
ip: z.string().ip().optional(),
userAgent: z.string().optional(),
timestamp: z.coerce.number().int().optional(),
+ id: z.string().optional(),
}),
});
@@ -55,7 +55,7 @@ export async function POST(request: Request) {
title,
tag,
timestamp,
- id,
+ id = '',
} = payload;
// Cache check
@@ -99,7 +99,7 @@ export async function POST(request: Request) {
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
const visitSalt = hash(startOfHour(createdAt).toUTCString());
- const sessionId = uuid(websiteId, ip, userAgent, sessionSalt, id ? id : '');
+ const sessionId = uuid(websiteId, ip, userAgent, sessionSalt, id);
// Find session
if (!clickhouse.enabled && !cache?.sessionId) {
diff --git a/src/tracker/index.js b/src/tracker/index.js
index 533a640a3..5c9b23a71 100644
--- a/src/tracker/index.js
+++ b/src/tracker/index.js
@@ -233,28 +233,34 @@
}
};
- const track = (obj, data) => {
- if (typeof obj === 'string') {
+ const track = (name, data) => {
+ if (typeof name === 'string') {
return send({
...getPayload(),
- name: obj,
- data: typeof data === 'object' ? data : undefined,
+ name,
+ data,
});
- } else if (typeof obj === 'object') {
- return send({ ...obj, ...getPayload().id });
- } else if (typeof obj === 'function') {
- return send(obj(getPayload()));
+ } else if (typeof name === 'object') {
+ return send({ ...name });
+ } else if (typeof name === 'function') {
+ return send(name(getPayload()));
}
return send(getPayload());
};
- const identify = (data, id = undefined) => {
- if (id && typeof id === 'string') {
+ const identify = (id, data) => {
+ if (typeof id === 'string') {
identity = id;
}
- /* Clear cache since this will result in another session */
+
cache = '';
- send({ ...getPayload(), data }, 'identify');
+ return send(
+ {
+ ...getPayload(),
+ data: typeof id === 'object' ? id : data,
+ },
+ 'identify',
+ );
};
/* Start */