Skip to main content
This is the long version of the Quickstart. If you just want the 5-minute happy path, start there. This guide covers everything around the edges: the full lifecycle from first line of code to recurring payouts.

Lifecycle overview

1

Design

Decide where ads go in your UI, which placements you need, and whether you’re using the SDK or calling the API directly.
2

Integrate

Install the SDK. Wire gravityContext() on the client, gravity.getAds() on the server, GravityAd (or your own renderer) in the UI.
3

Test

Keep production: false. Verify placements render, impressions fire on visibility, clicks route through clickUrl.
4

Install the pixel

Drop the Gravity pixel onto your site. One <script> tag — mints a visitor ID the SDK automatically forwards on every ad request, which tightens targeting and attribution. If you also open ad links inside a native in-app browser, add the in-app browser install on top.
5

Go live

Flip production: true. Watch the going-live checklist.
6

Optimize

Let experiments test ad designs against your real traffic with no integration changes.
7

Get paid

Monitor payouts in the dashboard. Revenue accrues per impression.

Pick placements

A placement is where an ad sits relative to your UI. Every ad request declares one or more. Common options: Each placement has a placement_id you pick — anything identifying the slot ("main", "mobile-footer", etc.). Keep them stable across requests; you’ll see per-slot metrics in the dashboard. You can request up to 10 placements per call and the engine returns an ad per slot (or null per slot with no fill).

Choose: SDK or API

Both hit the same engine. The SDK is a thin wrapper that handles context preparation, impression tracking, retry, and experiments. The API is what the SDK calls under the hood. Use the SDK when:
  • You’re on Node, TypeScript, Python, or React
  • You want a pre-built, server-managed ad component
  • You want managed experiments without integration changes
  • You want impression tracking to “just work”
Use the API directly when:
  • You’re on an unusual language / runtime
  • You render ads in a heavily custom way that can’t use GravityAd
  • You’re prototyping or building a CLI / non-UI surface
You’re not locked in either way. The API is fully supported and never going away.

Typical integration shapes

Next.js / App Router

Express

FastAPI / Python

Error handling

The SDK never throws. Failure modes: Your UI should always be safe to render with an empty ads array. Never block your LLM response on the ad fetch.

Going live checklist

See Going live. Short version: flip production: true, verify impressions land, confirm clicks route through clickUrl, watch the dashboard.

What’s next

Request ads

Server-side patterns in depth.

Show ads

Render ads with the official SDK component.

Pixel

Drop gr-pix.js on your site — SDK auto-picks up the visitor ID for better attribution. Optional WebView install for native apps.

Experiments

How the engine auto-optimizes creative mix for your traffic.