Skip to content

Commit

Permalink
Update - use uuid4 in environments that does not suppoer localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed Dec 18, 2023
1 parent 56a1856 commit 06d2638
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,14 @@ export const shortPoll = async (
}

export const generateOrRetrieveDistinctId = (): string => {
let distinctId = localStorage.getItem("posthog_distinct_id")
if (!distinctId) {
distinctId = uuidv4()
localStorage.setItem("posthog_distinct_id", distinctId)
if (typeof localStorage !== "undefined") {
let distinctId = localStorage.getItem("posthog_distinct_id")
if (!distinctId) {
distinctId = uuidv4()
localStorage.setItem("posthog_distinct_id", distinctId)
}
return distinctId
} else {
return uuidv4()
}
return distinctId
}

0 comments on commit 06d2638

Please sign in to comment.