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

getVideoData is not a function error #36

Closed
DanWilkerson opened this issue Mar 29, 2016 · 8 comments
Closed

getVideoData is not a function error #36

DanWilkerson opened this issue Mar 29, 2016 · 8 comments

Comments

@DanWilkerson
Copy link
Contributor

When the script binds to an element that already is an YT player, it breaks. We can fix this by checking to see if YT.get(elementId || 'widget' + n), where n is the count of YouTube iframes we're on. If this is the case, we might be able to attach an event listener.

@rmeekers
Copy link

rmeekers commented Apr 4, 2017

Dan, I still have this issue in a specific situation (this page). What exactly was the fix? The commit only contains an updated comment.

@DanWilkerson
Copy link
Contributor Author

@rmeekers Should've tagged this: 5162442#diff-2b793c9228aa48c6a2b22a75d366918bL151

Basically the issue was the code was calling new YT.Player() on all elements that might be YouTube videos, but sometimes YT.Player's had already been created with the element by other code (like yours). Now the script uses YT.get() first to see if a Player has already been initialized on the given DOM element, and uses the existing Player if so.

Try with the latest version and see if it solves your issues.

@rmeekers
Copy link

rmeekers commented Apr 6, 2017

@DanWilkerson as far as I can see, the binding goes fine.
The iframe gets detected and then this code is executed:

            if (typeof youTubeIframe.pauseFlag === 'undefined') {
              console.log('addYouTubeEvents_2');
                youTubeIframe.pauseFlag = false;
                player.addEventListener('onStateChange', function(evt) {
                    onStateChangeHandler(evt, youTubeIframe);
                });
            }

I've found some info about the getVideoData() function. It's an unsupported function and it seems that Google doesn't provide it in some cases. I'm not sure why. A Google YouTube developer said that we should not use that function because it's not supported and thus not reliable.

We should use the YouTube API instead by calling http://gdata.youtube.com/feeds/api/videos/$targetVideoId?v=2&alt=jsonc. Suggestion how to implement this?

@DanWilkerson
Copy link
Contributor Author

DanWilkerson commented Apr 6, 2017

@rmeekers That API was deprecated a little while ago and can no longer be used to retrieve title information; we actually switched to using .getVideoURL() a few versions back because of this. Update to the latest version and you'll be all set.

#34

@rmeekers
Copy link

rmeekers commented May 4, 2017

@DanWilkerson I still get this error for some videos. Even with the current version of the script. I tried debugging it but can't find out what's going wrong. Any suggestions where I can look?

e.getVideoUrl is not a function (script line 285 https://github.com/lunametrics/youtube-google-analytics/blob/master/src/lunametrics-youtube.gtm.js#L285)

@DanWilkerson
Copy link
Contributor Author

If you share a page where I can reproduce, I'd be happy to take a look!

@rmeekers
Copy link

I've sent it by email (contact form on your website) few days ago.

@DanWilkerson
Copy link
Contributor Author

I can't seem to see the page any longer, but I did take a look and my guess is that some code on the page is messing with the functionality of the plugin. I'd try having just the video and the YouTube tracking script, then adding back in other stuff until it breaks again.

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

No branches or pull requests

2 participants