Skip to content

Commit 0703fc6

Browse files
committed
fix: track login page correctly (coder#13618)
(cherry picked from commit 495eea4)
1 parent a9e5648 commit 0703fc6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

site/src/pages/LoginPage/LoginPage.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FC } from "react";
1+
import { useEffect, type FC } from "react";
22
import { Helmet } from "react-helmet-async";
33
import { useQuery } from "react-query";
44
import { Navigate, useLocation, useNavigate } from "react-router-dom";
@@ -24,10 +24,21 @@ export const LoginPage: FC = () => {
2424
const redirectTo = retrieveRedirect(location.search);
2525
const applicationName = getApplicationName();
2626
const navigate = useNavigate();
27-
2827
const { metadata } = useEmbeddedMetadata();
2928
const buildInfoQuery = useQuery(buildInfo(metadata["build-info"]));
3029

30+
useEffect(() => {
31+
if (!buildInfoQuery.data || isSignedIn) {
32+
// isSignedIn already tracks with window.href!
33+
return;
34+
}
35+
// This uses `navigator.sendBeacon`, so navigating away will not prevent it!
36+
sendDeploymentEvent(buildInfoQuery.data, {
37+
type: "deployment_login",
38+
user_id: user?.id,
39+
});
40+
}, [isSignedIn, buildInfoQuery.data, user?.id]);
41+
3142
if (isSignedIn) {
3243
// If the redirect is going to a workspace application, and we
3344
// are missing authentication, then we need to change the href location

0 commit comments

Comments
 (0)