Skip to content

Commit

Permalink
[hud] Tracking experiment: add a session id (#4812)
Browse files Browse the repository at this point in the history
  • Loading branch information
clee2000 authored Dec 13, 2023
1 parent f5f8c06 commit 980184f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions torchci/lib/track.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { randomBytes } from "crypto";
export function track(router: any, type: string, info: any) {
// Gets cleared when local storage is cleared but I think that's ok.
if (window.localStorage.getItem("session_tracking_id") === null) {
localStorage.setItem(
"session_tracking_id",
`${randomBytes(20).toString("hex")}-${Date.now()}`
);
}
const sessionIDFromStorage = localStorage.getItem("session_tracking_id");

fetch(`/api/track`, {
method: "POST",
body: JSON.stringify({
Expand All @@ -8,6 +18,7 @@ export function track(router: any, type: string, info: any) {
windowPathname: window.location.pathname,
routerPathname: router.pathname,
routerPath: router.asPath,
sessionID: sessionIDFromStorage,
}),
});
}

1 comment on commit 980184f

@vercel
Copy link

@vercel vercel bot commented on 980184f Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.