First video on lesson don't work

How to fix error with video player(youtube)

window.onYouTubeIframeAPIReady.resolve is not a function
at window.onYouTubeIframeAPIReady (VideoModule.445543cbf45955d6980f.6ae797ea7313.js:1)

Player just stuck like this:

But when I click on next lesson in this section, video working and when i back to first lesson, video working

Hi @Chack, we’ve got the same problem. It turned out that a problem was with the GTM script, that we added to a main template. The GTM initialization blocked the video player loading. We’ve solved it by adding 1 second Timeout for GTM initialization.
I suppose the same problem may occur with other analytics scripts.

2 Likes

Thanks, man!
I think add it to issue list or it fixed on other versions?

@Glib_Glugovskiy
Hello, how do I add the timeout to the script or could you share with us how the change you made was?

2 Likes

For me the way I did it in my cas is I moved the script tag that loads GTM to the end of HTML.

In my case the script was in head section of lms/templates/main.html template, so I moved it to the bottom i.e <GTM script goes here> </body> </html>.

My reasoning is that Browser gives lower prioity to the script tag in the bottom[1] there are other factors of course but in my case it worked this way .


  1. Check for more detials: Optimizing resource loading with Priority Hints ↩︎

I’ve came with the same situation. After adding Google Tag Manager and executing some changes on GTM the Youtube videos stopped to work on the Open edX.
I tried to put GTM js at the end of the HTML, but I still see the same problem sometimes, other refreshes works.
To fix it I when to the Google Analytics 4 > Property > Admin > Data Streams > Measuring and removed the “Videos”.

2 Likes

We recently upgraded to GA4 and to Tutor, thanks @IvoBranco that solved the issue for us after a few minutes.

Hi! I had the same problem and I disabled the videos from measuring.

@sambapete how can I upgrade tutor’s plugin to GA4? How did you do it?

Google 4 Analytics will be officially added to olive.4 later this month and palm.1 in June when Palm is released.

Since we have a fork of Open edX, we were able to add the snippet of code recommended by Google to our fork but at this time it doesn’t cover everything. I would suggest you wait for the “official” solution coming soon.

Can I follow these instructions?

https://docs.openedx.org/en/latest/site_ops/how-tos/google-analytics.html

1 Like

If you read the page, like I said in my previous answer, it says

As of May 2023 Google Analytics 4 is supported in most edx-platform LMS templates and the following micro-frontends (MFEs) in the upcoming Olive.4 and Palm named releases:

Learning
Profile
Authentication
Account
Discussions

So yes, it will work if you are running Olive.4 or Palm.1 when they are released. If you cannot wait until then, you will have to configure Google Analytics 4 yourself in a fork of edx-platform and a fork of the aforementioned MFEs.

And don’t forget to switch your properties from Google Analytics Universal to Google Analytics 4 if it isn’t done already.

Ok thanks!

I’m going to be submitting a fix upstream for this. After trying quite a few things (changes on the GA/GTM side were not possible in our case), a simple change in edx-platform/common/lib/xmodule/xmodule/js/src/video/01_initialize.js

from

                    window.onYouTubeIframeAPIReady = function() {
                        window.onYouTubeIframeAPIReady.resolve();
                    };

to

                    window.onYouTubeIframeAPIReady = function() {
                        _youtubeApiDeferred.resolve();
                    }

resolves the issue.