Skip to main content

Why server-side?

The Gravity pixel tracks page views and auto-detects some conversions client-side. But for the highest fidelity — especially for purchases, signups, and other backend-confirmed events — sending conversions server-to-server is more reliable:
  • More reliable — server-side calls aren’t affected by browser extensions or network conditions
  • Richer data — attach customer email, phone, order details, and line items your frontend doesn’t have
  • Deduplication — use event_id to prevent double-counting across pixel and server events
  • Offline conversions — attribute phone calls, in-store purchases, and CRM events back to ads

How it works

  1. The Gravity pixel runs on your site and captures attribution context automatically
  2. On conversion, your frontend reads window.gravityPixel.getCAPIData() and sends it to your backend alongside the order
  3. Your backend calls POST /gateway/events with the pixel context plus server-side details (email, order total, line items)

Step 1 — Install the pixel

If you haven’t already, add the pixel to every page:

Step 2 — Read pixel data on conversion

When the user completes a conversion (purchase, signup, etc.), call getCAPIData() and pass the result to your backend:
getCAPIData() is safe to call at any time after the pixel loads. If the user arrived via a Gravity ad click, the attribution fields will be populated. If not, they return null — the conversion still records, it just won’t be attributed to a specific ad.

Step 3 — Send the conversion from your backend

Merge the pixel data with your order details and POST to the Gravity gateway. Pick your language:
Include "test_event_code": "TEST123" to validate your payload without recording a real conversion. Remove it when you go live.

Event types

Custom event names are also accepted (e.g., "event_name": "DownloadWhitepaper").

User data fields

Attribution (from pixel)

These are automatically included when you use getCAPIData(): Pass the entire user_data object through unchanged from getCAPIData() whenever possible.

Device context (from pixel)

The client_context object is automatically included by getCAPIData(). It contains device and environment signals that improve conversion quality: Pass the entire client_context object through from your frontend to your backend, then include it in the CAPI request — no manipulation is needed on your end. Gravity uses these signals to improve attribution accuracy.

Customer identity (from your backend)

Add these server-side for richer matching:
PII fields (em, ph, fn, ln) can be sent as plaintext — the API normalizes and SHA-256 hashes them before storage. No plaintext PII is ever persisted. If you prefer to pre-hash, send 64-character hex strings and the API will detect and accept them as-is.
Always send the phone number (ph) when you have one. Most integrations send only email, but if your checkout or lead form collects a phone number, including it materially increases match and attribution rates — the phone hash is a first-class identity signal alongside email. It costs you nothing extra: send it as plaintext and the API hashes it for you.

Custom data

Response

Deduplication

Events are deduplicated by event_id + event_name within a 48-hour window. Always include a unique event_id (e.g., your order ID) to prevent double-counting — especially if you fire both a pixel conversion and a server-side conversion for the same purchase.

Authentication

Pass your API key as a query parameter or Authorization header:
or
Your API key is in Settings → Organization in the Gravity dashboard.

Batch events

Send up to 1,000 events per request by adding more objects to the data array. Each event is processed independently — partial failures don’t reject the batch.

Verify it’s working

Three checks, in order:
1

Validate your payload with a test event

Send a request with "test_event_code": "TEST123". A correct setup returns events_processed: 1 with status: "test_ok". Test events are validated end-to-end but never stored, so you can iterate safely.
2

Send a real event and check the response

Remove test_event_code and send a real conversion. You want status: "ok". Don’t worry if attributed is false — attribution depends on the user having clicked a Gravity ad. A 200 response with status: "ok" means your integration is working, attributed or not.
3

Confirm in the dashboard

Open Events Manager → Status in the Gravity dashboard. The Conversions API row shows whether we’re receiving your server-side events — it flips from No data yet to Active within a minute or two of your first real event, with a “last received” time.

Troubleshooting

Next

Pixel setup

Install the Gravity pixel on your site.