Skip to content

Commit 495eea4

Browse files
authored
fix: track login page correctly (#13618)
1 parent 43e45f4 commit 495eea4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

site/src/pages/LoginPage/LoginPage.tsx

Lines changed: 13 additions & 11 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";
@@ -26,10 +26,21 @@ export const LoginPage: FC = () => {
2626
const redirectTo = retrieveRedirect(location.search);
2727
const applicationName = getApplicationName();
2828
const navigate = useNavigate();
29-
3029
const { metadata } = useEmbeddedMetadata();
3130
const buildInfoQuery = useQuery(buildInfo(metadata["build-info"]));
3231

32+
useEffect(() => {
33+
if (!buildInfoQuery.data || isSignedIn) {
34+
// isSignedIn already tracks with window.href!
35+
return;
36+
}
37+
// This uses `navigator.sendBeacon`, so navigating away will not prevent it!
38+
sendDeploymentEvent(buildInfoQuery.data, {
39+
type: "deployment_login",
40+
user_id: user?.id,
41+
});
42+
}, [isSignedIn, buildInfoQuery.data, user?.id]);
43+
3344
if (isSignedIn) {
3445
if (buildInfoQuery.data) {
3546
// This uses `navigator.sendBeacon`, so window.href
@@ -85,15 +96,6 @@ export const LoginPage: FC = () => {
8596
isSigningIn={isSigningIn}
8697
onSignIn={async ({ email, password }) => {
8798
await signIn(email, password);
88-
if (buildInfoQuery.data) {
89-
// This uses `navigator.sendBeacon`, so navigating away
90-
// will not prevent it!
91-
sendDeploymentEvent(buildInfoQuery.data, {
92-
type: "deployment_login",
93-
user_id: user?.id,
94-
});
95-
}
96-
9799
navigate("/");
98100
}}
99101
/>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy