Proje: Okul Platform · Hub: Okul Platform — Conventions
GA event helpers belong in gaEvents.js, not in feature scripts
Rule
All gaSendEventXxx(...) helper definitions go in resources/assets/scripts/gaEvents.js. Functional scripts (general.js, app.js, page-specific files) only CALL these helpers — they never DEFINE them.
Why
- Single source of truth for event taxonomy and signatures.
- Changes to tracking shape (e.g., adding a field to
ga4EventParseAndSendpayload) touch one file. - Easier to audit: “what analytics does this app emit?” = grep one file.
- Build order enforces availability:
webpack.mix.jsconcatenatesgaEvents.jsBEFOREgeneral.js/app.js, so allgaSendEventXxxare globally available.
Existing helpers (as of 2026-04-14)
gaSendEventNavigation,gaSendEventLogin,gaSendEventSignUp,gaSendEventErrorgaSendEventArticle,gaSendEventFormOpen,gaSendEventFormClose,gaSendEventAchievementgaSendEventSchools,gaSendEventSocial,gaSendEventSearch,gaSendEventProfileActiongaSendEventCollegeAction,gaSendEventScholarship,gaSendEventAnnouncementgaSendEventDiscount,gaSendEventBanner,gaSendEventGallery,gaSendEventStepsgaSendEventOtp— OTP flow events (type=‘OTP’, captures_gaEventCat+_loginTriggerglobals internally; thin wrapper aroundgaSendEventLogin)
When adding a new event category
- Add
gaSendEventYyy(...)togaEvents.jsfollowing the existing pattern:function gaSendEventYyy(pageType_, action_, ...) { ga4EventParseAndSend('Yyy', 'gaEventYyy', { ... }); } - Use it at call sites in
general.js/app.js/blade inline scripts. Do NOT redefine the helper there. - If the helper needs sensible defaults (e.g., grabbing
_gaEventCatwhen caller doesn’t pass one), encapsulate that in the helper itself — call sites stay one-liners.
Caught case (2026-04-14)
OTP flow initially had a private sendOtpGaEvent(action, elementText) wrapper defined inside general.js AND duplicated inside app.js. User flagged this — helpers belong in gaEvents.js. Moved to gaEvents.js as gaSendEventOtp and call sites renamed.
Important must-track moments
Whenever a non-trivial FE feature is added (login variant, form flow, booking step), always wire up events. User-stated rule 2026-04-14: “fe tarafinda yapilan önemli değişimlerde mutlaka eventler eklenmeli.” Missing analytics on a new flow is a defect, not a nice-to-have.
Related
- 2026-04-14-otp-value-field-validation — OTP flow where this convention was codified
- 2026-04-14-fe-style-js-locations — broader FE file-location rules