Analytics & Tracking

Google Analytics 4 (GA4), consent, and custom events

Analytics & Tracking

This document describes how analytics work on the Cascadia Marquee site: Google Analytics 4 (GA4) via gtag.js, cookie consent, helper utilities, and the custom events we send.

Overview

  • Product analytics: Google Analytics 4 (measurement ID from NEXT_PUBLIC_GA_MEASUREMENT_ID).
  • Consent: GA4 and Microsoft Clarity load only when the visitor accepts Analytics in cookie preferences. Implementation reads localStorage.cookiePreferences and listens for cookie-preferences-updated.
  • Code: src/components/analytics/google-analytics.tsx loads gtag with next/script (lazyOnload). Custom events use src/lib/ga4-events.ts: scheduleGtagEvent (idle-scheduled, better INP on hot paths), pushGa4Event / gtagEvent for immediate sends. If gtag is not loaded yet, events queue on dataLayer.
  • Production only: src/lib/analytics-env.tsANALYTICS_ENABLED is true only when NODE_ENV === "production" so local dev does not pollute reports.

Marketing & ads pixels

Facebook Pixel, LinkedIn Insight, and optional Klaviyo load when Marketing cookies are accepted (src/components/analytics/pixel-events.tsx).

Custom events (GA4)

These are sent with scheduleGtagEvent unless noted. Parameter names use snake_case for GA4 custom dimensions.
Event nameTypical paramsWhen
form_startform_type, form_locationContact form mounted / meeting flow opened
form_abandonform_type, form_locationDialog closed without submit
generate_leadform_type, form_location, service, budgetContact form success
cta_clickcta_name, location, destination?Primary/secondary CTAs
navigation_clicklink_text, page_path, link_destination, link_typeNavLink and similar
case_study_clickcase_study_title, location, case_study_slug, tags, destinationCase study cards
meeting_dialog_openedlocationUser opens booking flow
meeting_date_selectedlocation, selected_dateCalendar choice
meeting_time_selectedlocation, selected_timeTime slot choice
meeting_bookedlocation, selected_date, selected_timeConsultation request succeeded
Register important parameters as custom dimensions in GA4 if you want them in reports.

What to configure in GA4

  1. Data streams — Ensure your web stream matches the site URL.
  2. Events — Mark generate_lead as a conversion if you use it as a goal.
  3. Custom dimensions — Map params you care about (e.g. form_location, cta_name).
  4. DebugView — Use GA debug mode or Realtime while testing production builds (pnpm build && pnpm start).
FileRole
src/lib/ga4-events.tspushGa4Event, scheduleGtagEvent, gtagEvent
src/lib/analytics-env.tsANALYTICS_ENABLED
src/components/analytics/google-analytics.tsxLoad GA4 after consent
src/components/analytics/microsoft-clarity.tsxClarity after consent
src/components/analytics/pixel-events.tsxMarketing pixels after consent

Privacy

Do not send names, emails, or free-form message text in analytics event params. See the privacy policy for disclosures shown to visitors.