> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trygravity.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send privacy signals

> Every ad request must carry the end user's privacy signals: TCF for EU, EEA, and UK users, and GPP (or US Privacy) plus GPC for US users.

Every ad request you send to Gravity must carry the end user's privacy signals in the `consent` object. Which signals you send depends on where the user is:

| Users in | Send | Fields |
| - | - | - |
| The EU, the EEA, or the UK | IAB TCF | `gdprApplies` and `tcfString` |
| The US | IAB GPP (or the older US Privacy string), plus Global Privacy Control | `gpp` and `gppSid` (or `usPrivacy`), plus `gpc` |

Read the values from your consent management platform (CMP) and from the user's browser or device. Send them exactly as you got them. Don't build or edit consent strings yourself. The official SDKs read most of these signals for you (see [What each SDK reads for you](#what-each-sdk-reads-for-you)).

## Why the signals are required

**You can lose partner demand.** Some demand partners decline to bid on requests that don't carry valid privacy signals. A request with no signals competes for less demand, so it tends to fill less often and at a lower price.

**Gravity serves contextual-only ads when the signals say so.** When `gdprApplies` is `true` and the request has no valid `tcfString`, or when `usPrivacy`, `gpp`, or `gpc` opts the user out, the engine serves contextual-only ads: it matches the ad to the conversation and processes no user identifiers for that request. Ads still serve, because contextual matching needs no personal data. By default, the engine also treats a request that has no consent signal and comes from an EU, EEA, or UK location as having no consent, and serves contextual-only ads. A request from a browser that sends `Sec-GPC: 1` is treated as `gpc: true`.

Sending the signals doesn't stop ads when the user consents. A user who has consented, or who hasn't opted out, gets the same ads as before. For the exact rules that the engine applies to each field, see [Consent](https://docs.trygravity.com/engine/contextual-ads.md#consent) in the API reference.

## The fields

| Field | Type | Where it comes from |
| - | - | - |
| `gdprApplies` | `boolean` | `gdprApplies` from the CMP's `__tcfapi`, or `IABTCF_gdprApplies` in an app. |
| `tcfString` | `string` | `tcString` from `__tcfapi`, or `IABTCF_TCString` in an app. |
| `gpp` | `string` | `gppString` from the CMP's `__gpp`, or `IABGPP_HDR_GppString` in an app. |
| `gppSid` | `number[]` | `applicableSections` from `__gpp`, or `IABGPP_GppSID` in an app. For example `[7]` for the US national section. |
| `usPrivacy` | `string` | The IAB US Privacy string from `__uspapi`, or `IABUSPrivacy_String` in an app. For example `"1YNN"`. Send it when your CMP doesn't support GPP. |
| `gpc` | `boolean` | `navigator.globalPrivacyControl` in a browser. In an app, `true` when the user turned down tracking on the device. |

## What each SDK reads for you

The `gpp`, `gppSid`, and `gpc` fields, and automatic GPP and GPC reading, need these minimum versions: `@gravity-ai/api` 1.5.0, `gravity-sdk` (Python) 0.6.0, `GravitySDK` (iOS) 1.3.0, and `ai.trygravity:gravity-sdk` (Android) 1.4.0. Earlier versions read only TCF and US Privacy. With an earlier version, send GPP and GPC with a [direct HTTP request](https://docs.trygravity.com/ai-platforms/request-ads.md).

| SDK | Reads automatically | What you send yourself |
| - | - | - |
| JavaScript (`@gravity-ai/api`) | In the browser, `gravityContext()` reads TCF from `__tcfapi`, US Privacy from `__uspapi`, GPP from `__gpp` (once its `signalStatus` is `ready`), and GPC from `navigator.globalPrivacyControl`. | Nothing in the browser. On a server, or when your CMP runs in a cross-origin frame, pass `consent` yourself. |
| Python (`gravity-sdk`) | `get_ads()` forwards the `consent` object in the `gravity_context` your client posts. It sets `gpc: true` when the incoming request has the `Sec-GPC: 1` header. | Pass `consent=` to `get_ads()` when your server has the signals. Otherwise make sure your client posts `gravity_context` with `consent`. |
| iOS (`GravitySDK`) | With `readCMPConsent: true` (the default), the TCF, US Privacy, and GPP keys (`IABGPP_HDR_GppString`, `IABGPP_GppSID`) that your CMP stores in `UserDefaults`. With `honorATT: true` (the default), `gpc: true` when the user didn't allow tracking. | Nothing when your CMP follows the IAB in-app spec. |
| Android (`ai.trygravity.sdk`) | With `readCMPConsent = true` (the default), the TCF, US Privacy, and GPP keys (`IABGPP_HDR_GppString`, `IABGPP_GppSID`) that your CMP stores in the default `SharedPreferences`. With `honorAdTrackingLimit = true` (the default), `gpc = true` when the device limits ad tracking. | Nothing when your CMP follows the IAB in-app spec. |

An explicit `consent` value replaces what the SDK detects as a whole. The SDK doesn't merge fields, so include every signal you have. In Python, an explicit `consent=` replaces `gravity_context.consent` from the client, and a `Sec-GPC: 1` header still adds `gpc: true`.

> [!NOTE]
>
> The SDKs send only the signals they find. If your app or page has no IAB CMP, the request carries no TCF or GPP signal, and you must pass the values yourself.

## Examples

Each example sends a US user's signals. For an EU, EEA, or UK user, send `gdprApplies: true` and `tcfString` instead.

```ts JavaScript theme={null}
import { gravityContext, gravityContextAsync } from '@gravity-ai/api';

// In the browser: the SDK reads __tcfapi, __uspapi, __gpp, and
// navigator.globalPrivacyControl. gravityContextAsync() waits for the CMP.
const gravity_context = await gravityContextAsync({
  sessionId: chatSession.id,
  user: { userId: currentUser.id },
});

// To set the values yourself (for example on a server), pass consent.
// It replaces the detected object as a whole, so include every signal.
const explicit_context = gravityContext({
  sessionId: chatSession.id,
  user: { userId: currentUser.id },
  consent: {
    gpp: 'DBABLA~BVQqAAAAAgA.QA',
    gppSid: [7],
    gpc: true,
  },
});
```

```python Python theme={null}
from gravity_sdk import Consent, Gravity

gravity = Gravity()

@app.post("/api/chat")
async def chat(request: Request):
    body = await request.json()
    # Without consent=, get_ads() forwards gravity_context.consent from the
    # client and adds gpc when the request has Sec-GPC: 1.
    # An explicit consent replaces gravity_context.consent as a whole.
    consent: Consent = {"gpp": "DBABLA~BVQqAAAAAgA.QA", "gppSid": [7], "gpc": True}
    result = await gravity.get_ads(
        request,
        body["messages"],
        [{"placement": "below_response", "placement_id": "YOUR_PLACEMENT_ID"}],
        consent=consent,
    )
```

```swift iOS theme={null}
// Default: the SDK reads IABTCF_*, IABUSPrivacy_String, IABGPP_HDR_GppString,
// and IABGPP_GppSID from UserDefaults, and maps an ATT denial to gpc.
let gravity = Gravity(apiKey: "YOUR_API_KEY")

// To set the values yourself, pass consent. It replaces what the SDK reads as a whole.
let result = await gravity.getAds(
    messages: messages,
    sessionId: "sess_abc123",
    userId: "user_123",
    placements: [Placement(placement: "below_response", placementId: "YOUR_PLACEMENT_ID")],
    consent: ConsentSignal(
        gpc: true,
        gpp: "DBABLA~BVQqAAAAAgA.QA",
        gppSid: [7]
    )
)
```

```kotlin Android theme={null}
// Default: the SDK reads IABTCF_*, IABUSPrivacy_String, IABGPP_HDR_GppString,
// and IABGPP_GppSID from SharedPreferences, and maps a tracking limit to gpc.
val gravity = Gravity(context, apiKey = "YOUR_API_KEY")

// To set the values yourself, pass consent. It replaces what the SDK reads as a whole.
val result = gravity.getAds(
    messages = messages,
    sessionId = "sess_abc123",
    userId = "user_123",
    placements = listOf(Placement("below_response", "YOUR_PLACEMENT_ID")),
    consent = ConsentSignal(
        gpc = true,
        gpp = "DBABLA~BVQqAAAAAgA.QA",
        gppSid = listOf(7),
    ),
)
```

```json HTTP theme={null}
{
  "messages": [{ "role": "user", "content": "What's a good running shoe?" }],
  "sessionId": "sess_abc123",
  "placements": [{ "placement": "below_response", "placement_id": "YOUR_PLACEMENT_ID" }],
  "user": { "id": "user_123" },
  "device": { "ip": "203.0.113.7", "ua": "Mozilla/5.0 ...", "device_type": "desktop", "os": "macos" },
  "consent": {
    "gpp": "DBABLA~BVQqAAAAAgA.QA",
    "gppSid": [7],
    "gpc": true
  }
}
```

An EU, EEA, or UK user's `consent` object looks like this:

```json theme={null}
{
  "consent": {
    "gdprApplies": true,
    "tcfString": "CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA"
  }
}
```

The strings in these examples are placeholders. Always send the strings that your CMP produces for the current user.

## Check your integration

1. Open your page or app with your CMP active, and accept or reject consent.
2. Inspect the ad request body, or the `gravity_context` your client posts, and confirm that `consent` holds the fields in the table at the top of this page.
3. Repeat for a user in each region you serve. A US user needs `gpp` (or `usPrivacy`), and `gpc` when the browser or device sends it. An EU, EEA, or UK user needs `gdprApplies` and `tcfString`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.