perf: clean up GTM init listeners after first successful initialization
@Nsanjayboruds is already working on this.
Since Apr 5, 2026.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 1.6k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 18
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.