nfl / react-gpt

A React display ad component using Google Publisher Tag
MIT License
145 stars 84 forks source link

Callback for "not in viewport" and such. #102

Open loqtor opened 5 years ago

loqtor commented 5 years ago

Hey,

More an enhancement than an issue probably, but I think that it'd be nice if the library gave you a way to know when the ad was not rendered because of reasons unrelated to it being empty or the script not being loaded.

The case I'm considering is either when the ad is not in viewport or the slot that matches the current viewport size is not properly defined.

The reason I'm raising this is because in my app the ads come from the API and one of them wasn't rendering, even though I had not changed anything on my end.

So, I started debugging and I noticed that one of the slots was empty, but Bling was not actually letting me know that the ad could not be rendered.

The change I'm thinking of is just having a prop that's called onError. It'd pass as a parameter an errorType (i.e.: OUT_OF_PAGE_ERROR when isInViewport is false, SLOT_ERROR when the slots are not properly defined) and you can then do whatever you need based on the type of error that took place.

I hope that made sense. Happy to send a pull request if you find it interesting.

Cheers!