Code

Every stage file in a Destination is an async function that receives a params object. This page is the reference for what's in params for each file and what the function should do with it.

All files are optional: leave a file empty and that stage is skipped. You never write wrappers, imports, or exports — only the function body.

edge/tag

Runs on the CDN edge for every tracked event. This is where most Destination logic lives.

Available on params:

  • payload — the event: eventName, eventId, pageUrl, pageTitle, referrer, locale, data (the event's standard fields, e.g. currency, value, orderId, contents).

  • userId — the EdgeTag user ID for this visitor.

  • user — hashable PII (email, phone, firstName, lastName, city, state, zip, country, …), if available.

  • customData — any custom tags you attached via the SDK.

  • providerData — click IDs and cookies captured per provider (e.g. fbp, fbc, gclid).

  • hostData — request metadata (userAgent, ip, country, city, region, timezone, postalCode).

  • origin, domain, platform — where the event came from.

  • secrets — your Variables as a plain object.

  • infra — your Infrastructure bindings (D1, KV, R2, Analytics Engine).

  • requestHandler(url, config) — make outbound HTTP requests.

  • userSave, userGet, providerSave — read and write the EdgeTag identity graph.

  • logger.log(...), logger.error(...) — visible in Simulation output.

edge/init

Runs once the browser SDK loads and invokes it. Use it to capture click IDs from URL parameters or cookies, detect new users, and read or write the identity graph before the first event fires.

Available on params:

  • userId, isNewUser

  • session{ isNewSession, sessionId } or null

  • cookies — raw cookie string from the request

  • hostData, secrets, infra

  • requestHandler, userSave, userGet, providerSave, logger

edge/user

Runs on the edge when user identity is sent (login, signup, profile update). Use it to sync identity to a CRM or resolve the user against an external system.

Available on params:

  • payload — the user fields being saved

  • userId, user, customData

  • hostData, secrets, infra

  • requestHandler, userSave, userGet, providerSave, logger

edge/scheduled

Runs periodically on a cron schedule (every 5 minutes). Use it for batch exports, periodic syncs, or cleanup jobs.

Available on params:

  • scheduledTime — a Date for the scheduled run

  • secrets, infra, logger, requestHandler

  • reporting.saveInDatabase(sql, bindings) — insert a row

  • reporting.saveBatchInDatabase(sql, bindingsArray) — batch insert

  • reporting.getFromDatabase(sql, bindings) — read

  • userKey.byRouteKey(key) — look up users by a routing key (email or user Id)

browser/init

Runs once in the browser on page load. Use it to load third-party scripts and initialize pixels, gated by consent.

Available on params:

  • userId, isNewUser, session

  • baseUrl — EdgeTag CDN base URL

  • manifest.variables — your client-side Variables

  • manifest.package, manifest.tagName, manifest.geoRegions

  • keyName, destination

  • consentData.consent, consentData.categories, consentData.consentSettings

  • sendTag(event) — forward an event to your own browser/tag

  • sendEdgeData(data, providers, options?) — persist data through the edge

  • getEdgeData(keys, callback) — read previously saved edge data

  • executionContext — a Map shared across calls in the same page load

browser/tag

Runs in the browser for every tracked event. Use it to call the third-party pixel's tracking API with the event data.

Available on params:

  • userId, sessionId, eventId, eventName, data

  • manifestVariables — your client-side Variables

  • destination

  • sendTag, getEdgeData, executionContext

browser/user

Runs in the browser when the user identity changes. Use it to update a third-party pixel with the latest user data.

Available on params:

  • userId, data, manifestVariables, destination

CDN API handlers

Each CDN API endpoint is a handler function. CDN APIs are browser-callable — no authentication — and are the right place for first-party endpoints your site needs to hit directly (for example /api/subscribe or /api/consent-preferences).

Available on params:

  • endpoint — the endpoint name

  • methodGET, POST, PUT, or DELETE

  • request — the standard Request object

  • secrets, infra, logger

Return a standard Response.

Server API handlers

Server APIs are EdgeTag backend authenticated server-only endpoints. They receive everything a CDN API does, plus params.currentUser with the authenticated user (userId, email, role, teamId, …). Use these for admin-only or server-to-server integrations.

Available web APIs

Inside edge files, you have the Workers runtime, which includes:

  • crypto.subtle.digest(...), crypto.randomUUID()

  • URL, URLSearchParams

  • TextEncoder, TextDecoder

  • atob, btoa

  • structuredClone

Browser files have the full browser API surface (window, document, fetch, localStorage, navigator, and so on).

Return values

Most stage files don't need to return anything — they're fire-and-forget.

  • edge/* and browser/* — returning nothing is fine. Browser files can return { skipEvent: true } to stop EdgeTag from continuing with this event.

  • CDN APIs and Server APIs — must return a Response.

circle-info

Throwing an exception in a stage file doesn't break the event pipeline for other channels. The error is captured and surfaced in Simulation output and your EdgeTag logs.

Last updated

Was this helpful?