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

Cannot add addEventListener #16

Open
rafaellop opened this issue Dec 9, 2016 · 2 comments
Open

Cannot add addEventListener #16

rafaellop opened this issue Dec 9, 2016 · 2 comments

Comments

@rafaellop
Copy link

I'm unable to use the addEventListener or I am doing it wrong.

I have successfuly installed the SDK + AdMob and Facebook Audience Network. The test suite shows interstitials and banners correctly. I can also show and display banners and interstitials in the apps, so everything seems to be configured and working properly. However, I'm suffering troubles with the addEventListener events. I'm simply not able to define them. My code is:

document.addEventListener('deviceready', function() {

  HeyzapAds.start("<PUBLISHER_KEY>").then(function() {
    // Start fetching ads
 
#55       HeyzapAds.BannerAd.addEventListener(HeyzapAds.BannerAd.Events.LOADED,
                function() {
                  // The ad is loaded.
                });
  
  }, function(error) {
    // Handle Error

  });
}, false);

Unfortunately console reports errors:

26799 TypeError: Cannot read property 'addEventListener' of undefined at app.js:55

What am I doing wrong?

And by the way, how can I use the native banners feature of Admob and FAN?

@vintage
Copy link

vintage commented Dec 9, 2016

It seems correct. I don't use banner ads in my app, so can't help here, but this one definitely works for me for reward videos:

HeyzapAds.IncentivizedAd.addEventListener(HeyzapAds.IncentivizedAd.Events.COMPLETE, () => {
    console.log('completed');
});

Can you check it in your codebase to see if it also returns undefined error?

@rafaellop
Copy link
Author

Konrad, thanks for the tip. I've checked and this IncentivizedAd listener doesn't return undefined error. All other (BannerAd and VideoAd) shows undefined errors. I've checked the plugin's /www/ads/InterstitialAds.js and /www/ads/IncentivizedAd.js and they looked almost the same. So I replaced VideoAd in all the examples for interstitials callbacs as found in the docs (https://github.com/Heyzap/heyzap-cordova/blob/master/docs/advanced.md) as:

HeyzapAds.VideoAd.addEventListener(HeyzapAds.VideoAd.Events.AVAILABLE,
  function(tag) {
    // An ad is available for display.
  });

to

HeyzapAds.InterstitialAd.addEventListener(HeyzapAds.InterstitialAd.Events.AVAILABLE,
  function(tag) {
    // An ad is available for display.
  });

and the callbacks for Interstitial ads started to bubble up.

I supposed the same issue is related to the BannerAd, but the code seemed OK. I've checked it one more time, typed instead of copy&paste and it ... stopped to complain undefined errors.

However, the LOADED type was never called back even if the banner is visible on the screen. So I changed the original plugin sources to use AVAILABLE like in the InterstitialAd/IncentivizedAd instead of LOADED and... it started to work.

I'll introduce the changes to the repository and I'll post a pull, but such errors are such a headache...

rafaellop pushed a commit to rafaellop/heyzap-cordova that referenced this issue Dec 9, 2016
VideoAd is nowhere defined in the plugin sources, InterstitialAd should be used instead.

Heyzap#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants