This commit is contained in:
Francis Cao 2025-04-24 22:42:44 -07:00
commit f659450f99
2 changed files with 14 additions and 3 deletions

View file

@ -18,6 +18,7 @@ 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(),
@ -54,6 +55,7 @@ export async function POST(request: Request) {
title,
tag,
timestamp,
id,
} = payload;
// Cache check
@ -99,7 +101,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);
const sessionId = uuid(websiteId, ip, userAgent, sessionSalt, id ? id : '');
// Find session
if (!clickhouse.enabled && !cache?.sessionId) {

View file

@ -46,6 +46,7 @@
url: currentUrl,
referrer: currentRef,
tag: tag ? tag : undefined,
id: identity ? identity : undefined,
});
const hasDoNotTrack = () => {
@ -240,14 +241,21 @@
data: typeof data === 'object' ? data : undefined,
});
} else if (typeof obj === 'object') {
return send(obj);
return send({ ...obj, ...getPayload().id });
} else if (typeof obj === 'function') {
return send(obj(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 */
@ -264,6 +272,7 @@
let cache;
let initialized;
let disabled = false;
let identity;
if (autoTrack && !trackingDisabled()) {
if (document.readyState === 'complete') {