JS Express Tracking: How to Set Up Server-Side Tracking in a Node.js Express App
Middleware that captures request context, one module that fans events out to Meta, Google and TikTok, and a shared event_id that stops double counting.

Key takeaways
-
Build one
lib/track.jsmodule that exportstrack(eventName, payload, context)and call it without awaiting, so a slow platform response never delays the user's request. -
Send the same
event_idto both the browser pixel and your server, because Meta deduplicates on theevent_nameplusevent_idpair and GA4 usestransaction_idfor the same job. -
Read
x-forwarded-forand take the first entry for the client IP when you're behind a proxy, sincereq.ipreturns the proxy address. -
Keep a 2 to 5 second
AbortControllertimeout on every outbound call and retry only 429 and 5xx responses with exponential backoff, capped at two or three attempts. - Hashing a SHA-256 email doesn't create a legal basis for sending it, so gate the send on the consent flag captured in middleware and return early when it's false.
Server-side tracking in Express means sending the same events from your Node server that your browser pixel sends, matched by a shared event_id. This guide covers that setup end to end: middleware, module code, tokens, retries and testing. If you came here for the other meaning, tracking a JS Express parcel with a carrier tracker, that's in the next section.
From your Node server, you post events to platform APIs like Meta's Conversions API or Google's Measurement Protocol. You pass a matching event_id with each browser pixel event, so the platforms count one conversion instead of two. If you want the concept settled before you write the code, what Meta's Conversions API is and why it sends events server-side explains the event_id matching in plain terms. Run the sends outside the request cycle. Hash identifiers before they leave your infrastructure. Store UTMs on the lead or order, so attribution survives after the event fires.
This js express tracking setup has four moving parts. A context middleware parses IP, user agent, click IDs and consent. One small module normalizes and hashes payloads, then fans them out to Meta, Google and TikTok. An event_id is shared between the pixel and the server. A failure path survives expired tokens and API timeouts. Browser pixels alone won't hold up. Third-party cookies are blocked by default in Chrome and Safari. iOS conversion data now routes through Apple's aggregation layer.
You'll get working middleware and module structure, plus the exact deduplication rules each platform applies. You'll also see where tokens belong and how to retry safely, and how to verify events actually arrived. It ends with a straight comparison of a Node client, server-side GTM and a hosted funnel builder. That helps you pick the one that fits where your events already live. If the comparison points you to Google Tag Manager, the step-by-step Meta CAPI setup with GTM walks the server container, the deduplication and the post-launch checks.
Why server-side tracking beats a browser pixel in an Express app
Server-side tracking means your Express server posts events to platform APIs. That covers Meta Conversions API, Google Measurement Protocol and TikTok Events API. You stop hoping a browser pixel fires. The event is built on your infrastructure, where you control the payload, the retries and the logs.
The clearest difference is cookies. Facebook's Conversions API transfers data via the server without third-party cookies, unlike the browser pixel. Third-party cookies are being blocked by default by all major browser providers such as Chrome and Safari. Anything that depends on them degrades over time. Before you rewrite anything, which events each side still sends, what Safari blocks anyway and what the migration costs lays out the switch without double counting.
Server events also survive failures that kill pixels. They avoid client-side issues like a user leaving the page before the pixel fires or an interrupted connection. They aren't affected by blocked scripts.
A purchase that completes while the browser tab closes still produces an event. The request that created it never left your server.
Privacy changes turned this from an optimization into a requirement. Apple's iOS 14 rules require users to actively allow cross-app and cross-site tracking, which cut the signals available to advertisers. On iOS, conversion data for optimization must pass through Apple's SKAdNetwork, which restricts and aggregates it before ad platforms see it. Which checkout signals survive iOS 14 and how to rebuild the purchase event on your server picks up at the checkout step, where Safari pixels lose the most purchases.
24 to 48 hours is the processing delay Apple's aggregation step adds before ad platforms receive iOS conversion data (Artefact)
Capture request context in Express middleware and store UTMs on the record
Add one app.use() near the top of your Express chain, above your routes. It builds a request context object that every server event reads from. Headers and cookies get parsed once.
Behind a proxy or load balancer, req.ip returns the proxy address. Read x-forwarded-for and take the first entry:
app.use((req, res, next) => {
const ip = (req.headers['x-forwarded-for'] || '').split(',')[0].trim()
|| req.socket.remoteAddress;
res.locals.ctx = {
ip,
userAgent: req.headers['user-agent'],
referrer: req.headers.referer,
fbclid: req.query.fbclid, gclid: req.query.gclid, ttclid: req.query.ttclid,
fbp: req.cookies._fbp, fbc: req.cookies._fbc,
utm: { source: req.query.utm_source, medium: req.query.utm_medium,
campaign: req.query.utm_campaign },
consent: req.cookies.cookie_consent === 'granted'
};
next();
});
Set your own first-party cookie on the landing page. That visitor ID follows the session to checkout. CAPI can key an event on browser ID, IP and user agent instead of an email. That is why it works for sites without a login and companies without a CRM.
Persist UTMs and click IDs on the lead or order row when you create it. Don't leave them only inside the event payload. Attribution then outlives the send. If you sell courses, templates or SaaS through affiliates, compare affiliate network fees, payout terms and structures before you commit. The consent flag sits next to the identifiers for a single-read check at send time. Sofunnels keeps UTM campaign attribution on the contact and order record on every plan, and exports it as CSV if you would rather not build that storage yourself.
- Add the context middleware above your routes
- Log one request to confirm
x-forwarded-forcarries the client IP, not the proxy - Set the first-party visitor cookie on the landing page
- Save UTMs and click IDs on the lead or order row at creation
- Save the consent flag alongside the identifiers
Build one JS Express tracking module for Meta, Google and TikTok
One module, one function, and every route calls it. Create lib/track.js and export track(eventName, payload, context), then import it in your lead, checkout and signup handlers instead of a platform SDK. Swapping destinations later never touches the routes.
Normalize the payload once, inside the module: event_name, event_time in Unix seconds, event_id, event_source_url, action_source, and a user_data object assembled from the context middleware. Every adapter reads that same shape.
Hash personal data before the request leaves your server. Lowercase and trim email, phone and name, convert the phone to E.164, then SHA-256 each field. Raw email in a payload is a leak waiting to happen. Those same normalization and hashing steps are what platforms match on, and how to raise event match quality without collecting more data covers the rest of them.
Each adapter posts to its own endpoint:
- Meta: the event array to your pixel's
/eventsedge on the Graph API, with the access token in the body. - Google: the Measurement Protocol collect endpoint, with a
client_id(reuse the GA cookie or generate a UUID) and anapi_secret. - TikTok: the Events API with
event_sourceset toweb, the sameevent_id, and the same hashed user data.
Adding a destination means writing one adapter inside lib/track.js, not editing every route that tracks something.
Call the module without awaiting it in the handler. A slow third-party response then never delays the user's request.
If you would rather not run that client at all, Sofunnels ships Meta CAPI and server-side Google tracking on its paid plans, so the funnel sends the events itself and you skip token storage and retry logic.
Stop double counting with a shared event_id between pixel and server
Generate the ID once per conversion, then send that same value to both the browser pixel and your Express endpoint. If the two calls carry different IDs, the platform reads them as two separate conversions and your cost per purchase looks better than it is.

Meta deduplicates on the pair: event_name plus event_id, matched inside a rolling window. A matching event_id with a different event_name still fails, so keep the string identical on both sides, including pluralization and past tense.
Use the order ID as the event_id for purchases, and a UUID or the form submission ID for leads. Store it on the order or contact record so support can trace a disputed conversion later. GA4 handles purchase deduplication with transaction_id, which needs to appear in both the browser event and the Measurement Protocol event.
Where access tokens live, and how to handle failures and retries
Keep tokens and API secrets in environment variables locally (.env, gitignored) and in your host's secret manager in production, never in the repo and never in client code.
Meta tokens expire. A system user token lasts longer than a short-lived user token, but you still have to watch the expiry date and rotate on a schedule. Error code 190 or 463 in the response body means the token is dead and events have already stopped.
Set a 2 to 5 second timeout with AbortController on every outbound call. Wrap the call in try/catch, log the status code and response body, and retry only 429 and 5xx responses with exponential backoff, capped at two or three attempts. At higher volume, push events onto a queue (BullMQ, SQS) and process them in a worker; CAPI accepts batched events per request. Return the user's HTTP response whether or not tracking succeeded, and alert on repeated failures rather than single ones.
Test that your server events actually arrived
Test in the platform's own debug view, not in your logs. Meta Events Manager has a Test Events tab: add a test_event_code to the payload and events appear in real time, tagged as server events. GA4 DebugView shows Measurement Protocol hits when you include debug_mode in the event params, and TikTok Events Manager uses the same test event code pattern.
Read the response body, not just the status code. A 200 can still carry an error message, and CAPI reports how many events it received, so compare that count against what you sent. When a mismatch is worth reporting to your team, how to write an email that gets a reply covers the format, the word counts and the follow-up cadence for the message you send.
Then fire a test purchase in Stripe test mode and match its event_id against the pixel's copy. Seeing the same ID twice in the platform means deduplication worked. One event passing doesn't mean the setup is finished, though: a checklist that runs from event map to production test covers the container sizing, dedup IDs and consent checks this single purchase won't catch. If Stripe Checkout handles the payment before your server hears about it, picking the right webhook event and confirming the purchase in Events Manager walks through that wiring and the deduplication on the Stripe side.
Consent: what you can send, hashing and honoring opt-outs
Hashing is a safeguard, not a permission. A SHA-256 email hash is still personal data in most privacy regimes because it can be re-linked to a person, so hashing doesn't create a legal basis for sending anything server-side.
Gate your tracking function on the consent flag the middleware captured. If it's false, return early before you build a payload. Keep a suppression list of hashed emails from opt-outs and check it in the same place, so a contact who unsubscribed doesn't re-enter through a background job.
Send the minimum: event name, event time, and only the identifiers needed for matching. The Conversions API gives you control over which data you send to Meta, while the basic pixel tracks everything visitors do by default.
This is engineering guidance, not legal advice. If you sell into the EU or UK, confirm your lawful basis with counsel before sending hashed identifiers server-side.
JS Express parcel tracking: where to look up a shipment
JS Express shipments are looked up by pasting the tracking number from your shipment email into a third-party carrier tracker that lists JS Express. If there's no English-language consumer tracking page, use a third-party tracker.
Copy the number exactly as it appears in the email. Make sure to copy the full tracking number exactly as it appears, as a missing prefix can return no result. That email is also the reliable source for who sent the parcel and which service was used.
The number format, the service area, the US delivery partner that runs the final leg, and JS Express contact details aren't covered by any source I can verify here. Confirm them through the seller or the tracker's JS Express carrier page instead of assuming a domestic network.
If you searched for "js express tracking" because you're instrumenting Express.js rather than a parcel, the section below covers server events, shared event IDs and deduplicating conversions.
Write a Node client, run server-side GTM, or use a hosted builder?
Pick the route that matches where your events already live. If orders, subscriptions and lead forms happen inside your app, a Node client is the shortest path: you own the senders, so you control every field in the payload. You also own token refresh, retries and platform API updates for as long as the app runs.
Server-side GTM moves the wiring into a UI, so marketers can add tags and triggers without a deploy. You still run a container and a server, and anything custom, like signing a payload or sending a field your platform doesn't expose, needs a community or custom template.
A hosted funnel builder removes the infrastructure. Sofunnels publishes template funnels with checkout, order bumps and first-party tracking, with no server to run. The trade-off is control: you send what the builder's event model exposes, not a payload you hand-assemble.
Mixed setups are common. Keep the Node client for product events, and let a hosted tool handle your funnel pages, so both write into the same analytics property.
| Approach | Setup | Payload control | Ongoing work |
|---|---|---|---|
| Node client in your app | Write middleware and senders, deploy | Full | Token and API version updates, per platform |
| Server-side GTM | Deploy a container, configure in the UI | High, via templates | Container and server upkeep |
| Hosted funnel builder | Build the funnel, tracking included | What the event model exposes | On the vendor |
Budget for maintenance either way. Platform API versions and token requirements change, so treat a few hours per platform per quarter as a working estimate, not a one-off setup cost.
Questions
Does server-side tracking still work if the visitor blocks JavaScript?
Yes. The event is built and sent from your Express server, so a blocked script or an extension that stops the pixel has no effect on the server call. You lose the browser pixel copy that pairs with it, but the Conversions API event still reaches Meta.
How do I pass UTM parameters to an Express server from a single-page app?
Read them from the URL on first page load, before client-side routing strips the query string, then store them in sessionStorage or a first-party cookie. Send them back with each API call, or post them to your server once and attach them to the lead or order row.
Do I need to hash the email if I only send _fbp and _fbc?
No. Hashing applies to personal fields like email, phone and name; _fbp and _fbc are cookie values you pass as-is. If your payload carries no email or phone, there is nothing to hash, but the consent check still applies to whatever identifiers you do send.
Why does my lead count double in Ads Manager even though I set up the server event?
Usually the two calls carry different event_id values, or the event names don't match exactly. Meta deduplicates on the event_name plus event_id pair, so generate the ID once and use that identical string in both the pixel and the server payload.
Can I run server-side tracking without a paid plan or a tag manager?
Yes. Server-side tracking is plain code: middleware, a sender module and an access token, with no tag manager required. Your costs are the server you already run plus the developer time to handle token rotation and API version updates.
Is JS Express tracking the same thing as tracking a JS Express parcel?
No. This article covers JavaScript and Express, the Node framework, for server-side event tracking. Parcel tracking refers to a courier service with a similar name and follows a completely different process. Same search phrase, unrelated topics.


