Gravity Conversions API
Server-side conversions to the Gravity Conversions API, for ads shown in AI assistants.
Gravity Conversions API is a server destination in the walkerOS flow:
Sends one event per request to `POST https://api.trygravity.com/gateway/events` with the API key as Bearer token, using raw HTTP (no SDK). Email, phone and names are normalised and SHA-256 hashed. Each event carries the walkerOS event id, or a mapped `event_id`, which Gravity uses with the event name to deduplicate for 48 hours.
Installation
npm install @walkeros/collector @walkeros/server-destination-gravity- Integrated
- Bundled
import { startFlow } from '@walkeros/collector';
import destinationGravity from '@walkeros/server-destination-gravity';
await startFlow({
destinations: {
gravity: {
code: destinationGravity,
config: {
settings: {
apiKey: process.env.GRAVITY_API_KEY,
},
},
},
},
});
A complete flow.json with this destination:
{
"version": 4,
"flows": {
"default": {
"config": {
"platform": "server"
},
"destinations": {
"gravity": {
"package": "@walkeros/server-destination-gravity",
"config": {
"settings": {
"apiKey": "$secret.GRAVITY_API_KEY"
}
}
}
}
}
}
}Configuration
This destination uses the standard destination config wrapper (consent, data, env, id, ...). For the shared fields see destination configuration. Package-specific fields live under config.settings and are listed below.
Settings
| Property | Type | Description | More |
|---|---|---|---|
apiKey | string | Gravity API key from Settings > Organization (owner or admin), sent as Bearer token | |
action_source | Where the conversion happened: website, app, email, phone_call, chat, physical_store, system_generated, pixel or other. Default: website. A mapped action_source wins | ||
doNotHash | Keys sent as mapped, without normalizing and hashing: their values must already be SHA-256 digests | ||
test_event_code | string | Test event code from Events Manager > Set up tracking: events are validated, not recorded | |
url | string | Endpoint | |
ip | any | boolean | Client IP, sent as user_data.client_ip_address. Resolves against { ingest, event }. Default: ["ingest.ip", "event.user.ip"]. false switches it off. A mapped ip_address wins. | |
userAgent | any | boolean | Client user agent, sent as user_data.client_user_agent. Resolves against { ingest, event }. Default: ["ingest.userAgent", "event.user.userAgent"]. false switches it off. A mapped user_agent wins. |
Mapping
This package does not define custom rule-level settings. For the standard rule fields (consent, condition, data, batch, name, policy) see mapping.
Examples
Custom event
Any mapped name that is not a Gravity standard event is sent as a custom event with that name.
{
"name": "demo booked",
"data": {
"user": "user-42"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"lang": "elb"
},
"custom": {
"completely": "random"
},
"user": {
"id": "us3r",
"device": "c00k13",
"session": "s3ss10n"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "ev-1700000902",
"trigger": "test",
"entity": "demo",
"action": "booked",
"timestamp": 1700000902000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}{
"name": "demo_booked",
"data": {
"map": {
"external_id": "data.user"
}
}
}sendServer("https://api.trygravity.com/gateway/events", "{\"data\":[{\"event_name\":\"demo_booked\",\"event_time\":1700000902,\"event_id\":\"ev-1700000902\",\"action_source\":\"website\",\"user_data\":{\"external_id\":[\"user-42\"]}}]}", {
"headers": {
"Authorization": "Bearer s3cr3t",
"Content-Type": "application/json"
}
})Lead
A demo request is sent to Gravity as a Lead with the hashed phone and every Gravity click parameter stored on the landing page.
{
"name": "demo request",
"data": {
"phone": "+49 151 23456789"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"grclid": "grc_1",
"grcpid": "cmp_2",
"gradid": "ad_3"
},
"custom": {
"completely": "random"
},
"user": {
"id": "us3r",
"device": "c00k13",
"session": "s3ss10n"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "ev-1700000901",
"trigger": "test",
"entity": "demo",
"action": "request",
"timestamp": 1700000901000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}{
"name": "Lead",
"data": {
"map": {
"phone": "data.phone",
"grclid": "globals.grclid",
"grcpid": "globals.grcpid",
"gradid": "globals.gradid"
}
}
}sendServer("https://api.trygravity.com/gateway/events", "{\"data\":[{\"event_name\":\"Lead\",\"event_time\":1700000901,\"event_id\":\"ev-1700000901\",\"action_source\":\"website\",\"user_data\":{\"ph\":[\"c0f8f0bebbbac96451ee8d8def84a02ae9e34c877775437cb9d458328315afa7\"],\"grclid\":\"grc_1\",\"grcpid\":\"cmp_2\",\"gradid\":\"ad_3\"}}]}", {
"headers": {
"Authorization": "Bearer s3cr3t",
"Content-Type": "application/json"
}
})Purchase with the Gravity pixel
The user_data and client_context of the Gravity pixel's getCAPIData(), sent along with the order, reach Gravity unchanged; the email is added hashed.
{
"name": "order complete",
"data": {
"id": "ORD-301",
"total": 99,
"currency": "EUR",
"gravity": {
"user_data": {
"grclid": "grc_7f3a",
"grcpid": "cmp_2",
"grpuid": "pub_5",
"gradid": "ad_3",
"grsig": "sig_9b1e",
"graid": "gra_4",
"visitor_id": "vis_81c2",
"session_id": "ses_42",
"client_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
},
"client_context": {
"timezone": "Europe/Berlin",
"screen": "1920x1080",
"viewport": "1440x900",
"platform": "MacIntel",
"connection": "4g"
}
}
},
"context": {
"shopping": [
"complete",
0
]
},
"globals": {
"pagegroup": "shop"
},
"custom": {
"completely": "random"
},
"user": {
"email": "Jane@Example.com"
},
"nested": [
{
"entity": "product",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "product",
"data": {
"id": "cc",
"name": "Cool Cap",
"size": "one size",
"price": 42
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "gift",
"data": {
"name": "Surprise"
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
}
],
"consent": {
"functional": true
},
"id": "ev-1700000903",
"trigger": "load",
"entity": "order",
"action": "complete",
"timestamp": 1700000903000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}{
"name": "Purchase",
"data": {
"map": {
"user_data": "data.gravity.user_data",
"client_context": "data.gravity.client_context",
"email": "user.email",
"value": "data.total",
"currency": "data.currency",
"order_id": "data.id"
}
}
}sendServer("https://api.trygravity.com/gateway/events", "{\"data\":[{\"event_name\":\"Purchase\",\"event_time\":1700000903,\"event_id\":\"ev-1700000903\",\"action_source\":\"website\",\"user_data\":{\"grclid\":\"grc_7f3a\",\"grcpid\":\"cmp_2\",\"grpuid\":\"pub_5\",\"gradid\":\"ad_3\",\"grsig\":\"sig_9b1e\",\"graid\":\"gra_4\",\"visitor_id\":\"vis_81c2\",\"session_id\":\"ses_42\",\"client_user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)\",\"em\":[\"8c87b489ce35cf2e2f39f80e282cb2e804932a56a213983eeeb428407d43b52d\"]},\"client_context\":{\"timezone\":\"Europe/Berlin\",\"screen\":\"1920x1080\",\"viewport\":\"1440x900\",\"platform\":\"MacIntel\",\"connection\":\"4g\"},\"custom_data\":{\"value\":99,\"currency\":\"EUR\",\"order_id\":\"ORD-301\"}}]}", {
"headers": {
"Authorization": "Bearer s3cr3t",
"Content-Type": "application/json"
}
})Purchase
A completed order is sent to Gravity as a Purchase with value, currency, the hashed email, the Gravity click id and the order id, also as event id for deduplication.
{
"name": "order complete",
"data": {
"id": "ORD-300",
"total": 249.99,
"currency": "eur"
},
"context": {
"shopping": [
"complete",
0
]
},
"globals": {
"grclid": "grc_7f3a"
},
"custom": {
"completely": "random"
},
"user": {
"email": "Jane@Example.com"
},
"nested": [
{
"entity": "product",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "product",
"data": {
"id": "cc",
"name": "Cool Cap",
"size": "one size",
"price": 42
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "gift",
"data": {
"name": "Surprise"
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
}
],
"consent": {
"functional": true
},
"id": "ev-1700000900",
"trigger": "load",
"entity": "order",
"action": "complete",
"timestamp": 1700000900000,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "express",
"platform": "server",
"url": "https://shop.example.com/checkout/complete"
}
}{
"name": "Purchase",
"data": {
"map": {
"email": "user.email",
"grclid": "globals.grclid",
"value": "data.total",
"currency": "data.currency",
"order_id": "data.id",
"event_id": "data.id"
}
}
}sendServer("https://api.trygravity.com/gateway/events", "{\"data\":[{\"event_name\":\"Purchase\",\"event_time\":1700000900,\"event_id\":\"ORD-300\",\"action_source\":\"website\",\"event_source_url\":\"https://shop.example.com/checkout/complete\",\"user_data\":{\"em\":[\"8c87b489ce35cf2e2f39f80e282cb2e804932a56a213983eeeb428407d43b52d\"],\"grclid\":\"grc_7f3a\"},\"custom_data\":{\"value\":249.99,\"currency\":\"EUR\",\"order_id\":\"ORD-300\"}}]}", {
"headers": {
"Authorization": "Bearer s3cr3t",
"Content-Type": "application/json"
}
})When it fails
- Invalid action source: A mapped action_source that is not one of Gravity's values fails the push with missing-input, not retryable, and nothing is sent. Reported as
failedwith codemissing-input. - Invalid currency: A currency that is not a 3-letter ISO 4217 code fails the push with missing-input, not retryable, and nothing is sent, so Gravity never books the value as USD. Reported as
failedwith codemissing-input. - Invalid value: A value that is negative or not a number fails the push with missing-input, not retryable, and nothing is sent. Reported as
failedwith codemissing-input. - Rejected by Gravity: Gravity answers HTTP 200 with the status error for the event: the push fails with transport, not retryable, and the event goes to the dead-letter queue. Test mode checks each event at once; a live request answers accepted and Gravity processes the event later. Reported as
failedwith codetransport.
Event name
The mapped name is sent as event_name: a Gravity standard event (Purchase, Lead, CompleteRegistration, Subscribe, StartTrial, InitiateCheckout, Schedule, …) or any custom name.
"mapping": {
"order": { "complete": { "name": "Purchase", "data": { "map": {
"email": "user.email",
"grclid": "globals.grclid",
"value": "data.total",
"currency": "data.currency",
"order_id": "data.id"
} } } }
}Attribution
Gravity attributes a conversion with the values its pixel collects. With the Gravity pixel on your site, call window.gravityPixel?.getCAPIData?.() in the browser and send its user_data and client_context along with the event, for example under data.gravity. Then map both objects as they are: Gravity asks for the pixel's user_data unchanged on every event, not single fields copied out of it. getCAPIData() returns null until the visitor consents.
"data": { "map": {
"user_data": "data.gravity.user_data",
"client_context": "data.gravity.client_context",
"email": "user.email"
} }Without the pixel, read Gravity's click parameters (grclid, grcpid, grpuid, gradid, grsig, graid, oppref) from the landing page URL, keep them with the session, and map every one of them on each conversion. grsig signs the others, so they go back unchanged.
Mapped data
| Field | Sent as |
|---|---|
user_data | user_data, as it is (the Gravity pixel's getCAPIData().user_data) |
email, phone | user_data.em, user_data.ph, as lists and hashed (see Hashing) |
first_name, last_name | user_data.fn, user_data.ln, one value each, hashed |
external_id | user_data.external_id, as a list, not hashed |
visitor_id, session_id | user_data.visitor_id, user_data.session_id |
grclid, grcpid, grpuid, gradid, grsig, graid, oppref | user_data, as they are |
ip_address, user_agent | user_data.client_ip_address, user_data.client_user_agent |
client_context | client_context, as it is (the Gravity pixel's getCAPIData().client_context) |
event_id | event_id, cut to 128 characters (default: the walkerOS event id) |
action_source | action_source, one of website, app, email, phone_call, chat, physical_store, system_generated, pixel or other (default: the action_source setting, else website) |
value, currency, order_id, contents, content_name, content_category, predicted_ltv | custom_data (currency uppercased; contents is a list of line items such as { id, quantity, item_price, title }, built with a loop) |
source_url | event_source_url (default: event.source.url) |
A key you map on its own wins over the same key in user_data, except the click parameters: those in user_data win, because grsig signs them as one set. Gravity counts a value without a currency as USD.
To count a conversion once when the pixel or a second server sends it too, map the same event_id everywhere, such as your order ID, and use the same event name: Gravity deduplicates on both for 48 hours, and an event without event_id uses the walkerOS event id.
A mapped key the destination does not read, a user_data key Gravity does not list, and a value of the wrong type are left out: the event is still sent, and the collector logs one ERROR line naming them. A value that is negative or not a number, a currency that is not a 3-letter code and an action_source Gravity does not list fail the event instead (see When it fails).
Hashing
The destination SHA-256 hashes four user_data keys before sending, whether they are mapped on their own or inside user_data:
| Key | Normalization before hashing |
|---|---|
em | Trim and lowercase. |
ph | Keep only digits, so +1 (555) 123-4567, 15551234567 and +15551234567 give the same hash. Include the country code. |
fn, ln | Trim and lowercase. Gravity states no rule for names. |
A list is hashed item by item, and an empty value, or one that is empty after normalization, is left out. fn and ln take one value: a list is left out and named in the ERROR line. A value that already looks like a hash is hashed again. If your values are already SHA-256 digests, add their keys to doNotHash: they are sent exactly as mapped. The pixel's user_data holds no key that is hashed, so it reaches Gravity unchanged.
Client IP and user agent
The destination sends the client IP and user agent by default. The ip and userAgent settings resolve against { ingest, event } and default to ["ingest.ip", "event.user.ip"] and ["ingest.userAgent", "event.user.userAgent"] (see the config.ingest recipe on the Express source). A mapped ip_address or user_agent wins, and so does a client_ip_address or client_user_agent in a mapped user_data. Set either setting to false to turn it off.
Consent
The quickstart sets no config.consent, so Gravity receives every event, whatever consent the event carries. To send only events with consent, add consent: { marketing: true } to config, next to settings (with several keys listed, one granted key is enough). An event without that consent is skipped or queued, depending on the collector's consentDenied. Server flows built by the CLI skip it and count it in skipped. With startFlow it waits in the destination's queue by default: a later event that carries consent does not release it, and only a walker consent command does, which then sends the waiting events of every user at once. Pass consentDenied: 'skip' to startFlow to skip such events instead (see Gate a destination with consent and consent-denied events on a server). Gravity asks that once a visitor withdraws consent, neither the pixel nor your backend sends anything more for them.
Delivery and testing
A live request answers accepted for each event, and Gravity stores and attributes the event later. The push counts as delivered, but only Events Manager shows whether the conversion arrived. While you set up a mapping, set test_event_code to the code from Events Manager > Set up tracking > CAPI test: Gravity then checks each event at once and does not store it, a valid event answers test_ok, and one it rejects fails the push. A made-up code checks the payload too, but only the Events Manager code unlocks the event for Conversions and CPA campaigns.
A response outside the 2xx range, a network error or no answer within 5 seconds fails the push with transport (with the HTTP status) or timeout, and the event goes to the dead-letter queue. 429 and 5xx are marked retryable, other 4xx not; nothing resends the event by itself. Without apiKey the destination does not start: every push answers failed with the code config. A rule with silent: true sends nothing.