GravityAd React component, or write your own component.
Before you start
- You get ads from your server with
gravity.getAds()orgravity.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
labelTextprop. - It requests
impUrlone time, when at least half of the ad is in the viewport. - It opens
clickUrlwhen the user clicks the ad. - It shows the
fallbackprop, or nothing, whenadisnull.
Show more than one placement
Each ad has aplacement_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:- On the server, set
supportsSpec: falseandenableFrames: falsein theGravityoptions. Then Gravity sends only ads that your component can show. - Show a clear ad label, for example “Sponsored”.
- Use
ad.clickUrlfor the link. Do not use the landing page URL (ad.url). - Request
ad.impUrlone time, when the ad becomes visible.
Troubleshoot
The ad does not show
The ad does not show
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.Impressions do not count
Impressions do not count
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.Clicks do not count
Clicks do not count
Make sure that the link opens
ad.clickUrl, not ad.url.