Destinations
Destinations are where Junction sends your events. Each destination is a plain object with three async functions — init, transform, and send — wired together by the collector at runtime.
Available Destinations
Section titled “Available Destinations”| Destination | Package | Runtime |
|---|---|---|
| Google Analytics 4 | @junctionjs/destination-ga4 | Client + Server |
| Amplitude | @junctionjs/destination-amplitude | Client + Server |
| Meta Pixel + CAPI | @junctionjs/destination-meta | Client + Server |
| Plausible | @junctionjs/destination-plausible | Client |
| HTTP (Generic) | @junctionjs/destination-http | Server |
Configuration Pattern
Section titled “Configuration Pattern”Every destination is registered on the collector via its config:
import { createCollector } from "@junctionjs/core";import { ga4 } from "@junctionjs/destination-ga4";
const collector = createCollector({ destinations: [ { destination: ga4, config: { measurementId: "G-XXXXXXXXXX", }, }, ],});Destinations are factory functions or pre-built objects — never classes. This keeps them tree-shakeable and easy to test.
Event Name Mapping
Section titled “Event Name Mapping”All destinations use a 3-tier fallback to resolve event names:
- Config override —
config.eventNameMap["product:viewed"]takes priority - Default map — each destination ships with sensible defaults for common events
- Generated name — if no mapping exists, the name is derived from
entity_action(or a destination-specific format)
// Example: override a single event name for GA4{ destination: ga4, config: { measurementId: "G-XXXXXXXXXX", eventNameMap: { "product:viewed": "my_custom_view_item", }, },}Default Event Mapping
Section titled “Default Event Mapping”| Junction Event | GA4 | Amplitude | Meta |
|---|---|---|---|
page:viewed | page_view | Page Viewed | PageView |
product:viewed | view_item | Product Viewed | ViewContent |
product:added | add_to_cart | Product Added | AddToCart |
order:completed | purchase | Order Completed | Purchase |
System Events
Section titled “System Events”The _system entity is reserved for Junction’s internal lifecycle events (e.g., _system:initialized). All destinations must return null from transform() for system events — they are never forwarded to external providers.
Writing a Custom Destination
Section titled “Writing a Custom Destination”Junction destinations implement the Destination interface:
interface Destination<TConfig> { name: string; version: string; consent: ConsentCategory[]; runtime: "client" | "server" | "both";
init: (config: TConfig) => Promise<void> | void; transform: (event: JctEvent, config: TConfig) => unknown | null; send: (payload: unknown, config: TConfig) => Promise<void>; onConsent?: (state: ConsentState) => void; teardown?: () => Promise<void> | void;}See the Contributing Guide for the full walkthrough on building a new destination.