Skip to main content
This page tells you how to show the ads that you get from Request ads. Use the GravityAd React component, or write your own component.

Before you start

  • You get ads from your server with gravity.getAds() or gravity.get_ads().
  • For React, you installed @gravity-ai/react:

Show an ad with React

GravityAd does these tasks for you:
  • It shows the ad design that Gravity selects for the ad.
  • It shows the “Sponsored” label. To change the text, use the labelText prop.
  • It requests impUrl one time, when at least half of the ad is in the viewport.
  • It opens clickUrl when the user clicks the ad.
  • It shows the fallback prop, or nothing, when ad is null.

Show more than one placement

Each ad has a placement_id field. Use it to put each ad in the correct slot. Show a slot only when it has an ad:

Show an ad with your own component

Use the official component when you can. If you must write your own component, do these steps:
  1. On the server, set supportsSpec: false and enableFrames: false in the Gravity options. Then Gravity sends only ads that your component can show.
  2. Show a clear ad label, for example “Sponsored”.
  3. Use ad.clickUrl for the link. Do not use the landing page URL (ad.url).
  4. Request ad.impUrl one time, when the ad becomes visible.
For request setup, see the JavaScript and React SDK guide.

Troubleshoot

Make sure that ads has an item for the slot. No ad for a slot is normal. Also make sure that your server sends the ads array to the client.
GravityAd sends the impression only when at least half of the ad is in the viewport. Scroll the ad into view. If you use your own component, make sure that it requests ad.impUrl.
Make sure that the link opens ad.clickUrl, not ad.url.