Skip to content

perf: clean up GTM init listeners after first successful initialization #7590

@Nsanjayboruds

Description

@Nsanjayboruds

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:

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions