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.

Added id as a parameter to identify and include it in the payload. Removed the usage of localstorage

perso18237ae0374d8ab
diff --git a/src/app/api/send/route.ts b/src/app/api/send/route.ts
index c520a02b2..0d62cd580 100644
--- a/src/app/api/send/route.ts
+++ b/src/app/api/send/route.ts
@@ -18,7 +18,7 @@ const schema = z.object({
payload: z.object({
website: z.string().uuid(),
data: anyObjectParam.optional(),
- identity: anyObjectParam.optional(),
+ id: z.string().optional(),
hostname: z.string().max(100).optional(),
language: z.string().max(35).optional(),
referrer: urlOrPathParam.optional(),
@@ -60,7 +60,7 @@ export async function POST(request: Request) {
title,
tag,
timestamp,
- identity,
+ id,
} = payload;
// Cache check
@@ -99,13 +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,
- identity ? JSON.stringify(identity) : '',
- );
+ const sessionId = uuid(websiteId, ip, userAgent, sessionSalt, id ? id : '');
// Find session
if (!clickhouse.enabled && !cache?.sessionId) {
diff --git a/src/tracker/index.js b/src/tracker/index.js
index 33651e61e..520d56eac 100644
--- a/src/tracker/index.js
+++ b/src/tracker/index.js
@@ -46,6 +46,7 @@
url: currentUrl,
referrer: currentRef,
tag: tag ? tag : undefined,
+ id: identity ? identity : undefined,
});
const hasDoNotTrack = () => {
@@ -233,33 +234,27 @@
};
const track = (obj, data) => {
- let identity;
- try {
- const parsedIdentity = JSON.parse(localStorage.getItem('umami.identity'));
- identity = parsedIdentity !== null ? parsedIdentity : undefined;
- } catch (error) {
- identity = undefined;
- }
if (typeof obj === 'string') {
return send({
...getPayload(),
name: obj,
data: typeof data === 'object' ? data : undefined,
- identity,
});
} else if (typeof obj === 'object') {
- return send({ ...obj, identity });
+ return send({ ...obj, ...getPayload().id });
} else if (typeof obj === 'function') {
- return send({ ...obj(getPayload()), identity });
+ return send(obj(getPayload()));
}
- return send({ ...getPayload(), identity });
+ return send(getPayload());
};
- const identify = data => {
- localStorage.setItem('umami.identity', JSON.stringify(data));
+ const identify = (data, id = undefined) => {
+ if (id) {
+ identity = id;
+ }
/* Clear cache since this will result in another session */
cache = '';
- send({ ...getPayload(), data, identity: data }, 'identify');
+ send({ ...getPayload(), data }, 'identify');
};
/* Start */
@@ -277,6 +272,7 @@
let cache;
let initialized;
let disabled = false;
+ let identity;
if (autoTrack && !trackingDisabled()) {
if (document.readyState === 'complete') {