Skip to main content

React SDK

Pass the ad returned by Gravity to GravityAd:
GravityAd automatically handles the placement design, fallback, impression and click tracking, disclosure, and feedback controls. For lead-form campaigns, pass the session ID and API key used for the ad request:
apiKey is used by the component in the browser (lead-form and feedback submissions), so it is visible to the page. Pass it down from your server with the ad response rather than referencing a server-only environment variable in client code — bundlers either drop the value or inline your server secret into the bundle.
The same component renders standard and lead-form ads.

JavaScript and TypeScript SDK

Set GRAVITY_API_KEY in your server environment.

Prepare context

In your client application, prepare the session and user context:
Forward the complete gravity_context to your server.

Request ads

Request ads in parallel with your LLM call:
gravity.getAds() returns { ads: [] } on no-fill or failure, so render the slot conditionally. Keep one stable sessionId per conversation.

Custom rendering

Use GravityAd unless you need a fully custom renderer. Custom renderers must open ad.clickUrl, request ad.impUrl once when the ad becomes visible, and show a clear ad disclosure.