mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Merge pull request #3334 from perso182/props-in-session-definition
Use the props passed to identify to determine sessions
This commit is contained in:
commit
0fd2d09dba
2 changed files with 14 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ const schema = z.object({
|
||||||
payload: z.object({
|
payload: z.object({
|
||||||
website: z.string().uuid(),
|
website: z.string().uuid(),
|
||||||
data: anyObjectParam.optional(),
|
data: anyObjectParam.optional(),
|
||||||
|
id: z.string().optional(),
|
||||||
hostname: z.string().max(100).optional(),
|
hostname: z.string().max(100).optional(),
|
||||||
language: z.string().max(35).optional(),
|
language: z.string().max(35).optional(),
|
||||||
referrer: urlOrPathParam.optional(),
|
referrer: urlOrPathParam.optional(),
|
||||||
|
|
@ -54,6 +55,7 @@ export async function POST(request: Request) {
|
||||||
title,
|
title,
|
||||||
tag,
|
tag,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
id,
|
||||||
} = payload;
|
} = payload;
|
||||||
|
|
||||||
// Cache check
|
// Cache check
|
||||||
|
|
@ -97,7 +99,7 @@ export async function POST(request: Request) {
|
||||||
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
|
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
|
||||||
const visitSalt = hash(startOfHour(createdAt).toUTCString());
|
const visitSalt = hash(startOfHour(createdAt).toUTCString());
|
||||||
|
|
||||||
const sessionId = uuid(websiteId, ip, userAgent, sessionSalt);
|
const sessionId = uuid(websiteId, ip, userAgent, sessionSalt, id ? id : '');
|
||||||
|
|
||||||
// Find session
|
// Find session
|
||||||
if (!clickhouse.enabled && !cache?.sessionId) {
|
if (!clickhouse.enabled && !cache?.sessionId) {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@
|
||||||
url: currentUrl,
|
url: currentUrl,
|
||||||
referrer: currentRef,
|
referrer: currentRef,
|
||||||
tag: tag ? tag : undefined,
|
tag: tag ? tag : undefined,
|
||||||
|
id: identity ? identity : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasDoNotTrack = () => {
|
const hasDoNotTrack = () => {
|
||||||
|
|
@ -240,14 +241,21 @@
|
||||||
data: typeof data === 'object' ? data : undefined,
|
data: typeof data === 'object' ? data : undefined,
|
||||||
});
|
});
|
||||||
} else if (typeof obj === 'object') {
|
} else if (typeof obj === 'object') {
|
||||||
return send(obj);
|
return send({ ...obj, ...getPayload().id });
|
||||||
} else if (typeof obj === 'function') {
|
} else if (typeof obj === 'function') {
|
||||||
return send(obj(getPayload()));
|
return send(obj(getPayload()));
|
||||||
}
|
}
|
||||||
return send(getPayload());
|
return send(getPayload());
|
||||||
};
|
};
|
||||||
|
|
||||||
const identify = data => send({ ...getPayload(), data }, 'identify');
|
const identify = (data, id = undefined) => {
|
||||||
|
if (id && typeof id === 'string') {
|
||||||
|
identity = id;
|
||||||
|
}
|
||||||
|
/* Clear cache since this will result in another session */
|
||||||
|
cache = '';
|
||||||
|
send({ ...getPayload(), data }, 'identify');
|
||||||
|
};
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
|
|
||||||
|
|
@ -264,6 +272,7 @@
|
||||||
let cache;
|
let cache;
|
||||||
let initialized;
|
let initialized;
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
|
let identity;
|
||||||
|
|
||||||
if (autoTrack && !trackingDisabled()) {
|
if (autoTrack && !trackingDisabled()) {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue