Headless Attribution
Track a referred visit and pass the Siren tracking id between your frontend and a WordPress installation running Siren.
Requires Siren Pro
Last updated: October 26, 2026
In a headless Siren install, the frontend and the WordPress backend share one piece of state: the tracking id that names the visitor’s opportunity, which links a visit to a collaborator. This page covers the canonical way to get that id when a referred visitor arrives, persist it across page loads, and send it back at conversion time. Everything here needs Siren Pro, which ships the event ingestion and visit tracking routes. Siren Cloud has no /track/visit route. A Stripe or Shopify site on Siren Cloud records visits with its tracking line, and a WordPress site records them through the Siren Cloud Connector.
The tracking id is the opportunity number Siren sends in the X-Siren-OID header, such as 318. Your frontend stores it and sends it back exactly as received.
Siren has two doors. The browser records a referred visit on /track/visit with no credentials. Everything else, including a visit tied to a user, comes from your server on /event/{slug} with credentials.
The flow
Visitor arrives on the headless frontend with ?ref=<collaborator>.
POST to the /track/visit route with the collaborator alias. No credentials.
200 OK with the opportunity number in X-Siren-OID.
Store X-Siren-OID in a first-party cookie or local storage for the attribution window.
Frontend sends the stored value back unchanged in the X-Siren-OID request header on the conversion call.
Siren resolves the opportunity and runs the standard conversion pipeline.
End-to-end this is about fifteen lines of code in a typical frontend:
// On the landing page, when ?ref=ABC123 is present.
// Re-POST whenever a ref is present so Siren's resolver can decide whether
// to merge with an existing opportunity or create a new one.
const ref = new URLSearchParams(location.search).get("ref");
if (ref) {
const existing = document.cookie.match(/siren_oid=([^;]+)/)?.[1];
const res = await fetch("/wp-json/siren/v1/track/visit", {
method: "POST",
headers: {
"Content-Type": "application/json",
...(existing && { "X-Siren-OID": existing }),
},
body: JSON.stringify({ collaboratorId: `tracking:${ref}` }),
});
const trackingId = res.headers.get("X-Siren-OID");
// Match max-age to your program's attribution window
// (/documentation/general/cookie-duration).
if (trackingId) document.cookie = `siren_oid=${trackingId}; path=/; max-age=2592000; Secure; SameSite=Lax`;
}
// On the conversion call (checkout, form submit, etc.).
// Omit the header entirely when there's no tracking id rather than sending an empty string.
const oid = document.cookie.match(/siren_oid=([^;]+)/)?.[1];
fetch("/api/checkout", {
method: "POST",
headers: { ...(oid && { "X-Siren-OID": oid }) },
body: payload,
});
The cookie can’t be HttpOnly, because the conversion-time fetch needs to read it. Keep Secure and SameSite=Lax in place so the cookie isn’t transmitted over HTTP and is sent on top-level navigations only.
That’s the whole shape. The rest of this page is what each step actually does.
Step 1: Track the visit
The frontend posts the visit to the /track/visit route, passing the collaborator’s tracking alias as collaboratorId. The tracking: prefix tells Siren the value is a referral code, not an internal ID. That means you can read ?ref= straight off the URL and forward it without a reverse lookup. The same alias system handles this on WordPress-rendered sites.
The route takes no credentials, so the browser calls it directly. It records the visit and nothing else, and it ignores a userId. To tie a visit to a WordPress user, send it from your server to /event/site-visited with an application password.
The response carries the visitor’s tracking id in the X-Siren-OID header, such as 318. Read it client-side and persist it for the next steps. Use the same number as a sale’s trackingId.
A Siren version older than the /track/visit route answers 404. If your frontend can ship before the plugin upgrade, send the visit to /event/site-visited once when that happens. Newer versions refuse an anonymous /event/site-visited with 401, so drop the fallback once every backend runs a version with the route.
Step 2: Persist the tracking id
The tracking id needs to survive across requests and page loads, but it doesn’t need to live forever. Siren’s standard attribution window decides how long it remains valid. Once that window closes, the opportunity expires regardless of what your frontend does.
The recommended pattern is a first-party cookie scoped to your frontend’s domain, with a lifetime that matches your intended attribution window. Local storage works, but it loses the opportunity if the visitor clears site data or switches browsers. Reach for it only if the cookie path is closed off.
If a returning visitor arrives with a new referral parameter, POST another visit to /track/visit with the new collaboratorId and let Siren’s resolver decide whether to merge or create a new opportunity. If you already have a tracking id stored, send it back as X-Siren-OID on the inbound POST so Siren uses it as the resolution starting point.
Step 3: Send the tracking id at conversion time
When the visitor takes a conversion action (checking out, submitting a form, or anything else your program attributes on), your frontend forwards the request to WordPress with the persisted tracking id in a custom header, exactly as Siren sent it:
X-Siren-OID: 4218
Siren’s response interceptor reads the header, resolves the opportunity, and feeds it into the same conversion pipeline that runs for native WordPress traffic. The interceptor also writes the resolved opportunity back to the response, so your frontend can refresh its stored value if Siren merged it with another opportunity or started a fresh one.
What that looks like in practice depends on what triggers the conversion. Three paths cover the common cases:
- WooCommerce. The Siren extension fires
SaleTriggereditself and picks up the header along with the rest of the request. Attribution lands automatically. - Direct conversion creates. Posting to the conversions endpoint requires admin auth, so this has to come from a server-side runtime.
- Non-WordPress commerce stack. Reporting through
/event/saleresolves the same header the same way.
The path into Siren changes. The header contract is constant.
Trust boundary worth understanding
X-Siren-OID is set by the browser on every conversion call. At the network boundary it’s attacker-controlled, and opportunity numbers are sequential, so the number proves nothing about who sent it.
Three things bound the abuse vector:
- Every event route except
/track/visitneeds credentials, and/track/visitrecords only an anonymous visit. A browser can’t report a sale or tie a visit to a user. - The conversions endpoint requires admin auth, so a stranger can’t manufacture conversions directly through it.
- Sale events (
/event/sale) come from a server with credentials, and get crediting decisions only when the rest of the payload represents real commerce: a real WooCommerce order, a real Stripe charge, etc. An attacker who can fabricate that has bigger problems than headless attribution.
Where this matters most is /track/visit. It’s unauthenticated by design and not rate-limited unless the install ships its own EventIngestionRateLimitMiddleware. A scripted caller can iterate referral codes and inflate visit counts. Sites running real money through the public path should plan for rate limiting, bot protection, or fraud review. The plugin gives you the extension point. The abuse posture is the install’s choice.
What failure looks like
Four failures show up on a first build:
- Unresolvable alias.
POST /track/visitwithcollaboratorId: "tracking:DOES_NOT_EXIST"falls through the alias resolver unchanged, then trips the validation middleware (collaborator ID must be numeric or resolve to one) and returns a 4xx with the error in the body. Treat this as “no attribution” rather than retrying. - Stale tracking id at conversion time. If the cookie holds a tracking id whose attribution window has closed, the conversion still goes through but lands without attribution. The response header in that case carries no replacement value. Surface this in your logs to detect window misconfigurations. A tracking id for a shopper whose data was erased lands the same way.
- CORS preflight refused.
OPTIONSrequests must be allowed andX-Siren-OIDmust appear inAccess-Control-Allow-Headers. Both are covered in the introduction’s CORS section. Siren listsX-Siren-OIDinAccess-Control-Expose-Headers, so JavaScript can read it. - Visit refused with
401. The frontend posts the visit to/event/site-visitedwithout credentials. Send browser visits to/track/visit.
The Siren marketing site you’re reading right now uses this exact pattern. See the REST API launch post for the broader story.