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 ga4EventParseAndSend payload) touch one file.
  • Easier to audit: “what analytics does this app emit?” = grep one file.
  • Build order enforces availability: webpack.mix.js concatenates gaEvents.js BEFORE general.js / app.js, so all gaSendEventXxx are globally available.

Existing helpers (as of 2026-04-14)

  • gaSendEventNavigation, gaSendEventLogin, gaSendEventSignUp, gaSendEventError
  • gaSendEventArticle, gaSendEventFormOpen, gaSendEventFormClose, gaSendEventAchievement
  • gaSendEventSchools, gaSendEventSocial, gaSendEventSearch, gaSendEventProfileAction
  • gaSendEventCollegeAction, gaSendEventScholarship, gaSendEventAnnouncement
  • gaSendEventDiscount, gaSendEventBanner, gaSendEventGallery, gaSendEventSteps
  • gaSendEventOtp — OTP flow events (type=‘OTP’, captures _gaEventCat + _loginTrigger globals internally; thin wrapper around gaSendEventLogin)

When adding a new event category

  1. Add gaSendEventYyy(...) to gaEvents.js following the existing pattern:
    function gaSendEventYyy(pageType_, action_, ...) {
        ga4EventParseAndSend('Yyy', 'gaEventYyy', { ... });
    }
  2. Use it at call sites in general.js/app.js/blade inline scripts. Do NOT redefine the helper there.
  3. If the helper needs sensible defaults (e.g., grabbing _gaEventCat when 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.