Skip to content

Commit ee09f4f

Browse files
committed
handle keypress too
1 parent 1f395da commit ee09f4f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
350350
};
351351

352352
let _collectWebVitals: undefined | (() => void);
353-
let lastClickTimestamp: number | undefined;
353+
let lastInteractionTimestamp: number | undefined;
354354

355355
/** Create routing idle transaction. */
356356
function _createRouteSpan(client: Client, startSpanOptions: StartSpanOptions, makeActive = true): void {
@@ -466,7 +466,11 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
466466
}
467467

468468
if (detectRedirects && optionalWindowDocument) {
469-
addEventListener('click', () => (lastClickTimestamp = timestampInSeconds()), { capture: true, passive: true });
469+
const clickHandler = (): void => {
470+
lastInteractionTimestamp = timestampInSeconds();
471+
};
472+
addEventListener('click', () => clickHandler, { capture: true, passive: true });
473+
addEventListener('keypress', () => clickHandler, { capture: true, passive: true });
470474
}
471475

472476
function maybeEndActiveSpan(): void {
@@ -582,7 +586,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
582586
startingUrl = undefined;
583587
const parsed = parseStringToURLObject(to);
584588
const activeSpan = getActiveIdleSpan(client);
585-
const navigationIsRedirect = activeSpan && detectRedirects && isRedirect(activeSpan, lastClickTimestamp);
589+
const navigationIsRedirect = activeSpan && detectRedirects && isRedirect(activeSpan, lastInteractionTimestamp);
586590
startBrowserTracingNavigationSpan(
587591
client,
588592
{
@@ -756,7 +760,7 @@ function setActiveIdleSpan(client: Client, span: Span | undefined): void {
756760
// The max. time in seconds between two pageload/navigation spans that makes us consider the second one a redirect
757761
const REDIRECT_THRESHOLD = 0.3;
758762

759-
function isRedirect(activeSpan: Span, lastClickTimestamp: number | undefined): boolean {
763+
function isRedirect(activeSpan: Span, lastInteractionTimestamp: number | undefined): boolean {
760764
const spanData = spanToJSON(activeSpan);
761765

762766
const now = dateTimestampInSeconds();
@@ -770,7 +774,7 @@ function isRedirect(activeSpan: Span, lastClickTimestamp: number | undefined): b
770774

771775
// A click happened in the last 300ms?
772776
// --> never consider this a redirect
773-
if (lastClickTimestamp && now - lastClickTimestamp <= REDIRECT_THRESHOLD) {
777+
if (lastInteractionTimestamp && now - lastInteractionTimestamp <= REDIRECT_THRESHOLD) {
774778
return false;
775779
}
776780

0 commit comments

Comments
 (0)