layer5 icon indicating copy to clipboard operation
layer5 copied to clipboard

perf: clean up GTM init listeners after first successful initialization

Open Nsanjayboruds opened this issue 7 months ago β€’ 1 comments

Description

gatsby-browser.js defers GTM initialization with both a timeout and interaction listeners (scroll, mousemove, touchstart), but listener cleanup is incomplete.

Current flow:

  • setTimeout(initGTM, 3500) triggers delayed initialization
  • interaction listeners also call initGTMOnEvent
  • cleanup only removes the listener for the single event that fired

If GTM initializes through timeout first, interaction listeners remain attached until each event type occurs, creating unnecessary runtime overhead.

Reference:

  • https://github.com/layer5io/layer5/blob/master/gatsby-browser.js

Expected Behavior

  • GTM should initialize exactly once (current behavior already does this via window.gtmDidInit).
  • After first successful initialization (timeout or interaction), all GTM init listeners should be removed immediately.
  • Delay documentation/comment should clearly match milliseconds used in code.

Screenshots

Not UI-specific. This is a runtime/event-listener behavior issue in client bootstrap logic.

Environment:

  • Host OS: Ubuntu Linux
  • Browser: Google Chrome (also browser-agnostic due to JS event handling)

Contributor Resources and Handbook

The layer5.io website uses Gatsby, React, and GitHub Pages. Site content is found under the master branch.

Join the Layer5 Community by submitting your community member form.

Nsanjayboruds avatar Apr 05 '26 05:04 Nsanjayboruds

Hey @CodexRaunak , @Rajesh-Nagarajan-11 , I’d like to work on this issue. Could you please assign it to me?

Nsanjayboruds avatar Apr 05 '26 05:04 Nsanjayboruds