Proje: Okul Platform
gaEvents.js depends on ga4Event() from includes.events.base
Symptom
Uncaught ReferenceError: ga4Event is not defined on a page that loads gaEvents.js via <script src="...">.
Root cause
resources/assets/scripts/gaEvents.js internally calls ga4Event(eventName, customEventName, parameters) inside ga4EventParseAndSend. That function is NOT defined in gaEvents.js — it lives in a Blade partial:
@include('includes.events.base')which outputs an inline <script> defining gaEvent() and ga4Event() (the latter pushes to window.dataLayer). gaEvents.js is a pure function library that assumes ga4Event is already on the global scope.
On public okul.com.tr pages, includes.events.base is included in the main layouts, so it’s always available. On separately-loaded pages (customer login, isolated landing pages), it must be included explicitly.
Fix
Include includes.events.base BEFORE the <script src> that loads gaEvents.js:
@include('includes.events.base')
<script src="{{ asset('assets/scripts/gaEvents.js') }}"></script>Caught on (2026-04-14)
Adding OTP GA events to customer/user/login.blade.php — gaEvents.js loaded, GTM B2B wired, but ga4Event is not defined on first call.
Rule (forward-looking)
Whenever you load gaEvents.js on a page, also include includes.events.base. Ideally the base partial should be bundled into gaEvents.js itself, but until that refactor: the include is a hard prerequisite.
Related: resources/views/mobile/customer/master_layout.blade.php redefines ga4Event inline for its context — same pattern, self-contained page.
Related
- 2026-04-14-ga-event-helper-location — event helpers in gaEvents.js
- 2026-04-14-customer-project-separate-bundle — customer pages don’t share public site’s script bundle