Sub topic 9
Server-side tracking and conversion APIs
This chapter assumes you know what a tag manager is, how a pixel fires in the browser, and what a conversion event is. It also assumes you have read the earlier chapters on browser restrictions and consent. The goal is to understand what server-side tracking changes, what it does not change, and how to build a conversion upload that respects consent.
What server-side tracking is
In a classic setup, the visitor's browser runs JavaScript tags from several vendors. Each tag collects data and sends it straight to that vendor's servers. This is client-side tracking.
In a server-side setup, the browser sends events to a server that you control. That server then forwards selected events to ad platforms and analytics tools. A conversion API is the vendor-facing half of this. It is an HTTP endpoint on an ad platform that accepts conversion events from your server instead of from a browser pixel. Examples include Meta's Conversions API, Google's Enhanced Conversions and offline conversion imports, TikTok's Events API, and similar endpoints from other platforms.
There are two common patterns:
- Server-side tag container. You run a tagging server (for example, a server-side Google Tag Manager container) on a subdomain of your site. The browser sends one request to it, and the server fans out to vendors.
- Direct server-to-server upload. Your backend, CRM, or data warehouse sends events straight to a platform API. This is typical for purchases, qualified leads, subscriptions, and offline sales.
Why teams adopt it
Server-side tracking addresses real technical problems.
- Blocked requests. Ad blockers and some browser protections block requests to known tracker domains. A request to your own subdomain is less likely to be blocked, though blocklists can and do target CNAME-cloaked and tracker-like setups.
- Cookie lifetime. Safari limits the lifetime of cookies set by JavaScript (
document.cookie) to a short period, commonly seven days, and in some cases 24 hours. Cookies set in an HTTPSet-Cookieresponse header from your own server are treated more favorably, provided the server is on your own domain and not just a CNAME to a third party's IP range. Safari's rules around CNAME and IP-matching for cloaked first-party servers are a known gotcha. - Page performance. Fewer vendor scripts in the browser means less JavaScript to download and run.
- Control over data. Your server can remove fields, hash identifiers, and block events before anything reaches a vendor.
- Reliable events for offline outcomes. Closed deals, refunds, subscription renewals, and in-store purchases never occur in a browser. Only a server-to-server upload can report them.
What it does not do
Server-side tracking is a delivery mechanism. It does not remove the need for permission.
- Consent still applies. Under GDPR and ePrivacy rules, storing or reading identifiers on a device generally needs consent, and sending personal data to an ad platform for advertising needs a legal basis, which is usually consent. Moving the request from a browser to a server does not change that. Regulators have said clearly that the legal obligations follow the data, not the technology.
- It is not a way around platform policies. Apple's App Tracking Transparency and browser protections reflect user choices. Using server-side forwarding to re-identify people who opted out can violate platform terms and privacy law.
- It does not create signal from nothing. If the visitor never gave you an identifier, your server has nothing to match on.
- It adds cost and work. You pay for hosting, you maintain the pipeline, and you own the failures. A broken server container loses all events at once.
The hosting and the data minimization are your responsibility. That is a benefit if you use it and a liability if you ignore it.
How matching works
When an ad platform receives a server event, it has to decide which ad interaction led to it. It uses these inputs:
- Click identifiers, such as
gclid,fbclid, orttclid, captured from the landing page URL and stored by you. These are usually the strongest signal for click-based attribution. - Browser identifiers, such as the platform's first-party cookie value, passed along from the browser.
- Customer identifiers, such as email address or phone number, normalized and hashed.
- Contextual fields, such as IP address, user agent, and event time.
The platform reports a match quality or coverage metric. Higher match rates give the platform more events to use for reporting and for optimizing bidding.
Hashing customer identifiers
Platforms generally ask for SHA-256 hashes of normalized identifiers. Normalization means trimming whitespace and lowercasing, so that the same email always yields the same hash. Platforms hash the emails of their own users the same way and compare the two values.
import hashlib
def hash_email(email: str) -> str:
"""Normalize and SHA-256 hash an email address before sending it to an ad platform."""
normalized = email.strip().lower()
return hashlib.sha256(normalized.encode("utf-8")).hexdigest()
print(hash_email(" [email protected] "))Platforms differ in their normalization rules. Some require removing dots from the local part of Gmail addresses, and phone numbers usually need to be in E.164 format (a country code and digits, such as +14155550123). Read each platform's documentation and test with its diagnostics tool.
Capturing consent and passing it along
A server-side pipeline needs the visitor's consent state at the moment it decides what to forward. The usual approach:
- The consent banner records the visitor's choices in the browser.
- The tag layer reads those choices before any tags run.
- Each event sent to your server carries the consent state, either as parameters or through the platform's consent signals.
- Your server applies rules: forward in full, forward with reduced data, or drop.
Google's consent mode is one such signal. Defaults are set to denied before tags load, and an update is sent when the visitor chooses.
// Google tag consent mode: set the defaults to denied before any tags load,
// then update them when the visitor makes a choice.
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
// Called by your consent banner when the visitor accepts.
function onConsentGranted() {
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted'
});
}When consent is denied, consent mode lets tags send limited, cookieless signals. The platform can then use them for modeled measurement, which a later chapter covers. For events you build yourself, you must enforce the choice in your own code.
First-party cookies and their limits
A first-party identifier lets you link a visitor's sessions on your own site. Set it only after consent where the law requires it.
// Set a first-party cookie from your own domain, only after the visitor has consented.
function setFirstPartyId(consented) {
if (!consented) return;
const id = crypto.randomUUID();
const maxAge = 60 * 60 * 24 * 90; // 90 days
document.cookie = `visitor_id=${id}; Max-Age=${maxAge}; Path=/; Secure; SameSite=Lax`;
}This is a first-party cookie, so SameSite=Lax is appropriate. Two limits still apply. Consent rules cover it, and some browsers cap the lifetime of cookies written by script, so the 90 days requested here may be shortened. Setting the cookie from your server in a Set-Cookie header avoids the script-written cap in most cases.
Deduplication
Many teams run the browser pixel and the server API together. The same purchase then arrives twice. Platforms deduplicate if both events carry the same event name and the same event ID.
Rules to follow:
- Generate one event ID per real-world event, in the browser or at order creation, and send it on both paths.
- Keep the event name identical on both paths.
Purchaseandpurchasemay be treated as different events on some platforms. - Send both paths within the platform's deduplication window, which is limited in time.
- Check the platform's diagnostics for duplicate or unmatched events after launch.
Without matching IDs, you will inflate conversion counts, and automated bidding will optimize against bad data.
Common errors
| Error | Result | Fix |
|---|---|---|
| Forwarding events regardless of consent | Legal exposure and platform policy violations | Check consent state on the server and drop or minimize events |
| Missing or mismatched event IDs | Double-counted conversions | Use one shared ID per event on both paths |
| Hashing without normalizing | Low match rates | Trim, lowercase, and follow each platform's format rules |
| Sending raw email or phone | Policy violations and data exposure | Hash before sending, over HTTPS only |
| Uploading conversions late | Missed optimization and attribution windows | Upload promptly, within the platform's maximum delay |
| Cloaked subdomain setup | Cookie lifetime benefits lost in Safari | Host on infrastructure under your own domain and IP range |
| No monitoring | Silent data loss when the server fails | Alert on event volume drops and platform error responses |
A minimal conversion upload design
A sound design for a purchase event has these steps:
- At order creation, generate an
event_idand store it with the order. - Store the click identifier and the consent state captured at the time of the click or checkout.
- When the order is confirmed, check that consent for advertising use was granted.
- If so, build the payload with the event name, time, value, currency,
event_id, click identifier, and hashed email. - Send it over HTTPS to the platform API. Log the response and retry on temporary errors.
- Keep a record of what was sent and why, so you can honor deletion and withdrawal requests.
When a customer withdraws consent, stop future uploads for that person. Where a platform offers a deletion or user-data removal path, use it.
Measuring whether it helped
Do not judge the project by a higher conversion count alone, because deduplication mistakes also raise the count. Better checks:
- Compare server-confirmed orders in your own system to conversions reported by each platform.
- Watch the match quality score and the share of events with a click identifier.
- Check the lift in measured conversions among consented traffic only, and keep the denied-consent group separate.
- Use an incrementality test, covered in a later chapter, to judge whether the extra reported conversions reflect real advertising impact.
Exercise
A retailer runs both a browser pixel and a server conversion API for purchases. Reported purchases doubled after launch, but orders in the store's own database did not. Name the most likely cause and two fixes.
Show answer
The most likely cause is duplicate counting: the same purchase is reported on both paths and the platform cannot match them. Fixes: generate one event ID per order and send it on both the browser and server events, and keep the event names identical on both paths. Then confirm in the platform's diagnostics that duplicates are being merged and compare reported purchases to the order database.
Exercise
A team says that moving all tags server-side means they no longer need a consent banner, because no cookies are involved. Explain why this is wrong.
Show answer
Consent rules apply to the data and its use, not to where the code runs. Sending personal data such as hashed email or identifiers to ad platforms for advertising generally needs a legal basis, usually consent, and reading or writing identifiers on the device is covered by ePrivacy rules. A server-side setup should read the visitor's consent state and forward, minimize, or drop events accordingly.