Skip to content

Commit babf8e4

Browse files
committed
feat: 모임 생성(url_created) GA4 이벤트 트래킹 추가
1 parent f8660bd commit babf8e4

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

app/create/page.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useCreateMeeting } from '@/hooks/api/mutation/useCreateMeeting';
77
import type { MeetingCreateRequest } from '@/types/api';
88
import { useToast } from '@/hooks/useToast';
99
import Toast from '@/components/ui/toast';
10+
import { sendGAEvent } from '@next/third-parties/google';
1011

1112
export default function Page() {
1213
const [meetingName, setMeetingName] = useState('');
@@ -123,7 +124,7 @@ export default function Page() {
123124

124125
const purposes = getPurposes();
125126

126-
// capacity 처리: "아직 안정해졌어요" 체크 시 30으로 설정
127+
// capacity 처리: "아직 안정해졌어요" 체크 시 10으로 설정
127128
const capacity = isParticipantUndecided ? 10 : participantCount || 1;
128129

129130
const requestData: MeetingCreateRequest = {
@@ -142,6 +143,27 @@ export default function Page() {
142143
const { meetingId } = result.data;
143144
console.log('생성된 ID:', meetingId);
144145

146+
// --- [GA4 이벤트 전송 로직 추가] ---
147+
if (typeof window !== 'undefined') {
148+
// 1. 브라우저 식별자(browser_id) 확인 및 생성 (Get or Create)
149+
let browserId = localStorage.getItem('browser_id');
150+
if (!browserId) {
151+
// 없으면 새로 발급해서 브라우저에 각인!
152+
const randomStr = Math.random().toString(36).substring(2, 15);
153+
browserId = `bid_${randomStr}${Date.now().toString(36)}`;
154+
localStorage.setItem('browser_id', browserId);
155+
}
156+
157+
// 2. 방 만든 브라우저가 누구인지 식별자를 담아서 이벤트 전송
158+
sendGAEvent('event', 'url_created', {
159+
meeting_url_id: meetingId,
160+
participant_count_expected: capacity,
161+
browser_id: browserId,
162+
entry_method: 'url_direct',
163+
});
164+
}
165+
// -----------------------------------
166+
145167
// purposes를 localStorage에 저장 (장소 추천 카테고리로 사용)
146168
const purposes = getPurposes();
147169
if (purposes.length > 0) {

0 commit comments

Comments
 (0)