Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onAdError event listener #3381

Merged
merged 6 commits into from
Dec 2, 2023

Conversation

avencat
Copy link
Contributor

@avencat avencat commented Nov 24, 2023

This adds an onAdError event listener so you can have ad errors when your ads fail to load. I managed to test it on Android by providing a fake url to adTagUrl, but not on iOS, I don't know how to trigger this event listener… I already use this listener on my project thanks to patch package but thought some people might find it useful so here it is! 😄

To test this PR, you have to enable ads in your project, see:
https://react-native-video.github.io/react-native-video/component/props#adtagurl and iOS and Android parts of https://react-native-video.github.io/react-native-video/installation

  • On iOS, add this to your Podfile:
$RNVideoUseGoogleIMA = true
  • On Android, add this to buildScript.ext section of your android/build.gradle file:
        RNVUseExoplayerIMA = true

Then, you should be able to do:

import { AdEvent, OnAdErrorData } from 'react-native-video'

const MyComponent = () => {
  const onAdError = ({
    code,
    message,
    type
  }: OnAdErrorData) => {
    console.log({
      code,
      message,
      type
    })
  }

  return (
    <Video
      adTagUrl='https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpremidpostoptimizedpodbumper&ciu_szs=300x250&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&cmsid=496&vid=short_onecue&correlator='
      onAdError={onAdError}
    />
  );
};

@freeboub
Copy link
Collaborator

code looks good, I just doubting on the added api.
don't you think the error should be added to the main ads callback onReceiveAdEvent ?
It will allow to manage all ads event with only 1 callback..

Can you also confirm you tried to build with IMA dependancy disabled ?

@avencat
Copy link
Contributor Author

avencat commented Nov 27, 2023

Hi @freeboub! I didn't test without IMA dependencies, I just fixed the issues, I think we can add an error event to onReceiveAdEvent if you prefer to manage it that way, yes, I'll make the changes! 😉

@avencat
Copy link
Contributor Author

avencat commented Nov 27, 2023

As I said in #3378 (comment) I use onReceiveAdEvent but with a different data name (I used data instead of adData to be more accurate), do you want me to merge this PR in #3378?

@freeboub
Copy link
Collaborator

As I said in #3378 (comment) I use onReceiveAdEvent but with a different data name (I used data instead of adData to be more accurate), do you want me to merge this PR in #3378?

No I really prefer small PRs! Thank you for the proposal!

@freeboub
Copy link
Collaborator

@avencat can you juste merge master branch please ?
I added actions to build all samples (with or without ads).
I will just ensure that PR doesn't break build !
Thanks

Copy link
Collaborator

@freeboub freeboub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, can you add the new even in doc please ?

@avencat avencat requested a review from freeboub December 1, 2023 07:07
@freeboub freeboub merged commit 596c02d into TheWidlarzGroup:master Dec 2, 2023
6 checks passed
@KrzysztofMoch KrzysztofMoch mentioned this pull request Dec 2, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants