Google Analytics 4
The GA4 plugin sends Funnel events to Google Analytics 4 through window.gtag. Because
Funnel’s events already follow the GA4 schema, this plugin passes them through unchanged. No
transformation needed.
What it tracks
Section titled “What it tracks”Every Funnel event is forwarded as a GA4 event with the same name and parameters, plus an
event_id (from the EventContext) for cross-platform
deduplication. setUser maps to gtag("set", ...) and consent maps 1:1 to Consent Mode v2.
Before you start
Section titled “Before you start”- A GA4 Measurement ID (looks like
G-XXXXXXXXXX) from your GA4 property. - The standard GA4 base snippet (gtag.js) loaded in your page
<head>, so thatwindow.gtagexists before Funnel runs. Funnel only callsgtag; it does not load it for you.
Install & initialize
Section titled “Install & initialize”import { Funnel } from "@sunwjy/funnel-client";import { createGA4Plugin } from "@sunwjy/funnel-client/ga4";
export const funnel = new Funnel({ plugins: [createGA4Plugin()], debug: true,});
funnel.initialize({ ga4: { measurementId: "G-XXXXXXXXXX", // Optional: forwarded to gtag("config", id, config) config: { send_page_view: false }, },});Track an event
Section titled “Track an event”funnel.track("purchase", { currency: "KRW", value: 29000, transaction_id: "T-1",});Verify
Section titled “Verify”- Enable
debug: trueon theFunnelto log each dispatch to the console. - Set
config: { debug_mode: true }and open GA4 DebugView in the Google Analytics UI. - Inspect outgoing
gtagcalls in the browser DevTools Network tab (requests togoogle-analytics.com).
- SSR-safe: when
window(orwindow.gtag) is unavailable,track,setUser, andsetConsentquietly skip. Nothing throws. - The
configfield is forwarded verbatim togtag("config", measurementId, config), so you can control GA4 SDK behavior (send_page_view,cookie_domain,anonymize_ip, etc.). setConsentmirrors Google Consent Mode v2 signals one-to-one (ad_storage,analytics_storage,ad_user_data,ad_personalization).