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.

Refactored index.js

perso182224961447cba
diff --git a/src/tracker/index.js b/src/tracker/index.js
index fa5a30e9d..33651e61e 100644
--- a/src/tracker/index.js
+++ b/src/tracker/index.js
@@ -235,23 +235,24 @@
const track = (obj, data) => {
let identity;
try {
- identity = JSON.parse(localStorage.getItem('umami.identity'));
+ const parsedIdentity = JSON.parse(localStorage.getItem('umami.identity'));
+ identity = parsedIdentity !== null ? parsedIdentity : undefined;
} catch (error) {
- identity = null;
+ identity = undefined;
}
if (typeof obj === 'string') {
return send({
...getPayload(),
name: obj,
data: typeof data === 'object' ? data : undefined,
- identity: identity !== null ? identity : undefined,
+ identity,
});
} else if (typeof obj === 'object') {
- return send({ ...obj, identity: identity !== null ? identity : undefined });
+ return send({ ...obj, identity });
} else if (typeof obj === 'function') {
- return send({ ...obj(getPayload()), identity: identity !== null ? identity : undefined });
+ return send({ ...obj(getPayload()), identity });
}
- return send({ ...getPayload(), identity: identity !== null ? identity : undefined });
+ return send({ ...getPayload(), identity });
};
const identify = data => {