Amplitude
The Amplitude plugin connects Funnel to Amplitude product analytics. It forwards Funnel’s
GA4-standard events to Amplitude through window.amplitude, converting each event name to
Title Case (add_to_cart → Add To Cart).
What it tracks
Section titled “What it tracks”Every Funnel event is forwarded with a Title-Cased name:
| Funnel event (GA4) | Amplitude event |
|---|---|
page_view |
Page View |
view_item |
View Item |
add_to_cart |
Add To Cart |
purchase |
Purchase |
| …every other event | Title Case of the GA4 name |
Event parameters pass through, with an items array flattened into Amplitude-friendly
properties. For purchase and refund, the GA4 value is mapped to Amplitude’s revenue.
Each event sets insert_id from Funnel’s eventId for server-side deduplication.
Before you start
Section titled “Before you start”- An Amplitude API key.
- The Amplitude Browser SDK loaded in your page, so
window.amplitudeexists before Funnel runs.
Install & initialize
Section titled “Install & initialize”import { Funnel } from "@sunwjy/funnel-client";import { createAmplitudePlugin } from "@sunwjy/funnel-client/amplitude";
export const funnel = new Funnel({ plugins: [createAmplitudePlugin()], debug: true,});
funnel.initialize({ amplitude: { apiKey: "your_api_key", // forwarded to amplitude.init(apiKey, options) (optional) options: { serverZone: "EU" }, },});consentRequired: true is optional. When set, events are dropped until analytics_storage
is granted through funnel.setConsent(...).
Track an event
Section titled “Track an event”funnel.track("purchase", { currency: "USD", value: 99, transaction_id: "T-4004",});This calls amplitude.track("Purchase", { currency: "USD", revenue: 99, transaction_id: "T-4004", insert_id: "..." }).
Verify
Section titled “Verify”- Set
debug: trueon the Funnel to log each dispatch in the console. - Use Amplitude’s User Look-Up or Live stream to see events arrive in real time.
- SSR safe. When
window(orwindow.amplitude) is absent, the plugin does nothing. funnel.setUser(...)callsamplitude.setUserId(user_id)and sets remaining properties via anamplitude.Identify()instance (a plain object is ignored by the real SDK).funnel.resetUser()callsamplitude.setUserId(null)(logout).- Only
purchaseandrefundremapvalue→revenue; all other events keepvalueas-is. - Use
options.serverZone: "EU"for EU data residency.