Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the useTracker hook to accept a single event object instead of rest parameters and updates the sendGAEvent call. Feedback points out that sendGAEvent requires a single object with an event property to function correctly with Google Tag Manager and highlights that the signature change is a breaking change for existing implementations.
| return ({ action, value }: GAEventParams) => | ||
| sendGAEvent('event', `${category} ${action}`, { value }); |
There was a problem hiding this comment.
@next/third-parties/google 라이브러리의 sendGAEvent 함수는 내부적으로 window.dataLayer.push를 호출하는 래퍼입니다. GTM(Google Tag Manager)이나 GA4에서 이벤트를 정상적으로 수집하려면 event 속성을 포함한 단일 객체를 인자로 전달해야 합니다. 현재처럼 여러 개의 인자를 개별적으로 전달하면 GTM에서 이벤트를 인식하지 못해 데이터가 누락됩니다.
또한, 함수의 시그니처가 가변 인자(...value)에서 단일 객체({ action, value })로 변경되었습니다. 이 훅을 사용하는 기존 코드들에서 타입 오류나 런타임 에러가 발생할 수 있는 파괴적 변경(Breaking Change)이므로 주의가 필요합니다.
참고로 GA4에서 value 파라미터는 주로 수치형 데이터를 위해 예약되어 있으므로, 문자열 정보를 전달할 때는 다른 파라미터 이름을 사용하거나 이벤트 명에 포함시키는 것이 좋습니다.
| return ({ action, value }: GAEventParams) => | |
| sendGAEvent('event', `${category} ${action}`, { value }); | |
| return ({ action, value }: GAEventParams) => | |
| sendGAEvent({ event: `${category} ${action}`, value }); |
✅ 작업 내용
📝 참고 자료
♾️ 기타