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
edge/tagRuns 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
edge/initRuns 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,isNewUsersession—{ isNewSession, sessionId }ornullcookies— raw cookie string from the requesthostData,secrets,infrarequestHandler,userSave,userGet,providerSave,logger
edge/user
edge/userRuns 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 saveduserId,user,customDatahostData,secrets,infrarequestHandler,userSave,userGet,providerSave,logger
edge/scheduled
edge/scheduledRuns periodically on a cron schedule (every 5 minutes). Use it for batch exports, periodic syncs, or cleanup jobs.
Available on params:
scheduledTime— aDatefor the scheduled runsecrets,infra,logger,requestHandlerreporting.saveInDatabase(sql, bindings)— insert a rowreporting.saveBatchInDatabase(sql, bindingsArray)— batch insertreporting.getFromDatabase(sql, bindings)— readuserKey.byRouteKey(key)— look up users by a routing key (email or user Id)
browser/init
browser/initRuns 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,sessionbaseUrl— EdgeTag CDN base URLmanifest.variables— your client-side Variablesmanifest.package,manifest.tagName,manifest.geoRegionskeyName,destinationconsentData.consent,consentData.categories,consentData.consentSettingssendTag(event)— forward an event to your ownbrowser/tagsendEdgeData(data, providers, options?)— persist data through the edgegetEdgeData(keys, callback)— read previously saved edge dataexecutionContext— aMapshared across calls in the same page load
browser/tag
browser/tagRuns 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,datamanifestVariables— your client-side VariablesdestinationsendTag,getEdgeData,executionContext
browser/user
browser/userRuns 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 namemethod—GET,POST,PUT, orDELETErequest— the standardRequestobjectsecrets,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,URLSearchParamsTextEncoder,TextDecoderatob,btoastructuredClone
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/*andbrowser/*— 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.
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?

