DEV Community

Peter Panda
Peter Panda

Posted on

Server-Side Conversion Events for Meta and TikTok: A Minimal Architecture for Small Teams

Browser pixels lose data. Ad blockers, browser privacy features and consent choices all reduce what the platforms see, and the ad algorithms optimize worse as a result. Both Meta (Conversions API) and TikTok (Events API) accept server-side events. Large teams use a tag server or a CDP. Small teams can do it with much less. Here is a minimal setup we use with overseas clients.

The pieces

  1. Your backend already knows when an order, signup or qualified lead happens.
  2. A small sender module that posts events to Meta and TikTok.
  3. A deduplication key shared between pixel and server events.
  4. A consent check so you only send what the user agreed to.

Deduplication is the part people get wrong

If you keep the browser pixel and add server events, the platforms will double count unless both events carry the same event ID. Generate the ID when the action starts (for example, the order ID), pass it to the pixel call in the browser, and send the same ID from the server.

// browser
fbq('track', 'Purchase', {value: 49, currency: 'USD'}, {eventID: orderId});
ttq.track('CompletePayment', {value: 49, currency: 'USD', event_id: orderId});
Enter fullscreen mode Exit fullscreen mode

The server sender

import hashlib, time, requests

def sha(v): return hashlib.sha256(v.strip().lower().encode()).hexdigest()

def send_meta(order, pixel_id, token):
    payload = {"data": [{
        "event_name": "Purchase",
        "event_time": int(time.time()),
        "event_id": order["id"],
        "action_source": "website",
        "user_data": {"em": [sha(order["email"])],
                      "client_ip_address": order["ip"],
                      "client_user_agent": order["ua"]},
        "custom_data": {"value": order["total"], "currency": "USD"}}]}
    requests.post(f"https://graph.facebook.com/v19.0/{pixel_id}/events",
                  params={"access_token": token}, json=payload, timeout=10)
Enter fullscreen mode Exit fullscreen mode

TikTok's Events API has a similar shape with its own field names. Keep the two senders separate; their schemas drift independently.

Hash, minimize, respect consent

Hash personal data before sending, send only fields that improve matching, and skip the call entirely if the user declined marketing cookies in regions where that applies.

Send asynchronously

Never block checkout on an ad platform API call. Put the event on a queue and retry on failure with a cap.

Verify in the platform tools

Both platforms provide test event tools. Send a test purchase, confirm the event arrives once (deduplicated), and check the match quality score.

Connect it to your reporting

Server events help the ad platforms. Your own reporting still needs UTMs and CRM fields so you can compare platforms fairly. We describe that side in how we attribute AI and ad leads with UTMs and CRM fields.

The whole setup is a few hundred lines of code. For a small team spending a meaningful budget on Meta or TikTok, it is one of the highest-return engineering tasks available.

Published by PandaWM, an overseas marketing team based in Hong Kong.

Top comments (0)