Fix: Google Analytics and GTM initialize on every render causing duplicate events
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- nextjs, react, typescript
- Domain
- frontend
Research direction
Start in Head.tsx at HeadComponent and inspect how analytics initialization currently runs during rendering. Move the initialization and pageview behavior to mount-time handling, then verify that rerendering the component does not produce duplicate analytics initialization or pageview events.
Written by the indexing model from the issue text.
Description
I was exploring the codebase and noticed a potential issue in Head.tsx regarding how we handle analytics initialization.
Currently, the ReactGA.initialize TagManager.initialize, and ReactGA.pageview calls are placed directly inside the component body of HeadComponent
if (typeof window !== 'undefined' && window.location.hostname.includes('asyncapi.com')) {
TagManager.initialize({ gtmId: 'GTM-T58BTVQ' });
ReactGA.initialize('UA-109278936-1');
ReactGA.pageview(window.location.pathname + window.location.search);
}
Because this logic isn't wrapped in a useEffect or componentDidMount, it executes every time the HeadComponent re-renders.
We should wrap this logic in a useEffect hook with an empty dependency array. This ensures it only runs once when the component mounts, which is the intended behavior for a page view.
@princerajpoot20 do you guys think this needs to be done , would like to know your thoughts on this!! , i could raise a pr for the same
- Dominant language
- TypeScript
- Stars
- 717
- Forks
- 1.2k
- Avg merge
- 14h 59m
- Merged PRs (30d)
- 40
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.
More from asyncapi/website
-
📑 docs
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
[Improve]:Use top-level` updatedAt` instead of `timelineItems` connection for score calculation Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
area/typescript triaged
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
stale triaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
triaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in asyncapi/website
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100