-
Notifications
You must be signed in to change notification settings - Fork 1.5k
perf: clean up GTM init listeners after first successful initialization #7590
Copy link
Copy link
Open
Labels
framework/gatsbyGatsby relatedGatsby relatedhelp wantedExtra attention is neededExtra attention is neededkind/bugSomething isn't workingSomething isn't working
Description
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.
- 📚 See contributing instructions.
- 🎨 Wireframes and designs for Layer5 site in Figma (open invite)
- 🙋🏾🙋🏼 Questions: Discussion Forum and Community Slack.
Join the Layer5 Community by submitting your community member form.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
framework/gatsbyGatsby relatedGatsby relatedhelp wantedExtra attention is neededExtra attention is neededkind/bugSomething isn't workingSomething isn't working